title: Function works as intended but when converted into an onEdit() function it doesn't run till the end
body: <p>I have made this nice code which does the job if I fire it from the script editor, which is to check some dates and send out some e-mails if some dates are too close to each other, but if I convert it into an onEdit() function and do an edit it launched but doesn't finishes which is such a shame. The code I am using is below. Does anyone know why it does this?</p>
  
  <pre><code>function onEdit1() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var readMeSheet = ss.getSheetByName("ReadMe");
    var today = new Date();
    readMeSheet.getRange(37,1).setValue(Utilities.formatDate(today,"GMT", "dd-MMM-yyyy"));
    var dateOfLastCheck = new Date(readMeSheet.getRange(37,2).getValue());
    var overdueCheck = Math.floor(today.getTime()-dateOfLastCheck.getTime());
    var days = (1000*60*60*24);
    var temp = overdueCheck/days;
  
    if ( overdueCheck/days &gt; 2 ) {
    readMeSheet.getRange(37,2).setValue(Utilities.formatDate(today,"GMT", "dd-MMM-yyyy"));
    var lastActiveSheet = ss.getActiveSheet().getName();
    ss.setActiveSheet(ss.getSheetByName('Active Jobs'));
    var fEmptyRow = getFirstEmptyRow('Active Jobs');
  
    for ( i=2; i&lt;fEmptyRow; i++ ){
    var jobDate = new Date(ss.getActiveSheet().getRange(i,15).getValue());
    var dif = Math.floor(jobDate.getTime()-today.getTime());
      if ( dif/days &lt; 3) {
        switch(ss.getActiveSheet().getRange(i,8).getValue()){
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
            var emailExtension = "@*******.com";
            break
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
          case "*******":
            var emailExtension = "@*******.*******.com";
            break
        }
  
        switch(ss.getActiveSheet().getRange(i,8).getValue()){
            case "*******":
            case "*******":
            case "*******":
            case "*******":
            case "*******":
                var teamLeader = ", *******@*******.com";
                break
            case "*******":
            case "*******":
            case "*******":
            case "*******":
                var teamLeader = ", *******@*******.com";
                break
            case "*******":
            case "*******":
                var teamLeader = ", *******@*******.com";
                break
        }
  
                           if (MailApp.getRemainingDailyQuota() &gt; 0) {
                              //GmailApp.sendEmail(ss.getActiveSheet().getRange(i,8).getValue() + emailExtension + teamLeader, 'Please be aware the job ID'+ss.getActiveSheet().getRange(i,1).getValue()+' less than 3 days away from the report out date',
                                GmailApp.sendEmail("*******@*******.com", 'Please be aware the job ID'+ss.getActiveSheet().getRange(i,1).getValue()+' less than 3 days away from the report out date',
                                'Hello, could you please amend the job if it is not on schedule to complete within the next 3 days and inform the PAT leader? If everything is on track please disregard this e-mail. :)')
                                                                     }  
                                                                   }
                                  }
    ss.setActiveSheet(ss.getSheetByName(lastActiveSheet));
  }
  }
  
  function getFirstEmptyRow(sheet) {
    var spr = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);
    var column = spr.getRange(2,1,spr.getMaxRows()-1,1);
    var values = column.getValues(); // get all data in one call
    for(var ct = values.length-1; ct &gt; -1; ct--){
      if(values[ct][0] != ""){
        var emptyRow = ct + 3;
        break;
      }
    }
    return emptyRow;
  }
  </code></pre>