title: Exceeded maximum execution time google sheets script work around
body: <p>I have a script that runs a function for a set of data that is drawn from a master sheet. Each time the function runs, it draws and processes a data set based on a date designated in a cell in a sheet (cell A3). The date in this cell is updated via a 'for' loop for a date range that I specified. the script can execute 5 complete runs (aka each run execute the function for a day worth of data) of these loops before I run into "Exceeded maximum execution time" some time during the 6th run. All of my data are already saved to the spreadsheet in a continual updating fashion after every run so what I have to do after five cycles is to manually restart the run for another 5 days starting at the 6th day by modifying my script. I am reading about <a href="https://stackoverflow.com/questions/7854573/exceeded-maximum-execution-time-in-google-apps-script">time driven trigger</a> where someone is pausing the script every 5 minutes to get around the 6 minutes execution time limit but it does not suit my needs because I would like a break after every 5 cycles, (not based on time). What I need is to write a script where after running 5 cycles, the script can break and then resume running again for another 5 cycles. Here is what my code looks like:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function runMultipleDates() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
  
    var start = new Date("2018-11-05");
    var end = new Date("2018-11-09"); 
    var step = 1;
  
    for (var date1 = start; date1 &lt;= end; date1.setDate(date1.getDate() + step)) {
      var date2 = new Date(date1.getTime());
      date2.setDate(date2.getDate() + 1);
      ss.getSheetByName('Time Range').getRange("A3").setValue(date2);
      runEverything();
  
    };
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you can see, right now I am adjusting the start and end date manually for 5 days, let it run and then restart the process again by adjusting my script start date to be 2018-11-09 and end date to be 2018-11-13 for the next run. This function, on its own, is to able to run for far more than 5 days cycles without the execution time restriction. So the question is whether there is away to pause the script and resume running after 5 cycles of the above script. Any help is greatly appreciated.</p>