title: Changing onEdit functions to timer trigger
body: <p>I've inherited some sheets and the scripting is beyond my understanding and my research hasn't given me an answer unfortunately! I need one of the scripts to run at midnight each night instead of using the onEdit trigger. This also means that the script will need to look for all entries that meet the requirements not just the one that was last edited.</p>
  <p>What the scripts currently do:</p>
  <ul>
  <li>On edit, function &quot;CRMarchive&quot; checks column 26 of sheet A, if cell edited contains &quot;Yes&quot;, copies the whole row and pastes it to sheet B, then deletes row from sheet A.</li>
  <li>Also on edit, another function &quot;Sort&quot; will order sheet B based on the dates in column 3, latest first.</li>
  </ul>
  <p>What I need the scripts to do:</p>
  <ul>
  <li>Function &quot;CRMarchive&quot; does the same thing but at midnight and for <em>any</em> rows on sheet A that have &quot;Yes&quot; in column 26.</li>
  <li>Function &quot;Sort&quot; then sorts all entries in sheet B.</li>
  </ul>
  <p>I've sorta figured out that it's the active sheet/range bit that's not allowing me to use time based triggers but my messing has only yielding limited success, i.e., I can make it move one row that meets the criteria by manually firing the script but that's it.</p>
  <pre><code>function CRMarchive(){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = ss.getActiveSheet();
    var r = s.getActiveRange();
  
    if(s.getName() == &quot;Promotions/Retain&quot; &amp;&amp; r.getColumn() == 26 &amp;&amp; r.getValues() == &quot;Yes&quot;) {
      var row = r.getRow();
      var numColumns = &quot;25&quot;
      var targetSheet = ss.getSheetByName(&quot;Archive - Promotions/Retain&quot;);
      var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
      s.getRange(row, 1, 1, numColumns).moveTo(target);
      s.deleteRow(row); 
    }
   if(s.getName() == &quot;Dev+Save/Int/Welc+Nurture&quot; &amp;&amp; r.getColumn() == 26 &amp;&amp; r.getValue() == &quot;Yes&quot;) {
      var row = r.getRow();
      var numColumns = &quot;25&quot;
      var targetSheet = ss.getSheetByName(&quot;Archive - Dev+Save/Int/Welc+Nurture&quot;);
      var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
      s.getRange(row, 1, 1, numColumns).moveTo(target);
      s.deleteRow(row);
    }
   if(s.getName() == &quot;Reactivation&quot; &amp;&amp; r.getColumn() == 26 &amp;&amp; r.getValue() == &quot;Yes&quot;) {
      var row = r.getRow();
      var numColumns = &quot;25&quot;
      var targetSheet = ss.getSheetByName(&quot;Archive - Reactivation&quot;);
      var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
      s.getRange(row, 1, 1, numColumns).moveTo(target);
      s.deleteRow(row);
    }
   if(s.getName() == &quot;Conversions&quot; &amp;&amp; r.getColumn() == 26 &amp;&amp; r.getValue() == &quot;Yes&quot;) {
      var row = r.getRow();
      var numColumns = &quot;25&quot;
      var targetSheet = ss.getSheetByName(&quot;Archive - Conversions&quot;);
      var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
      s.getRange(row, 1, 1, numColumns).moveTo(target);
      s.deleteRow(row);
    }
   if(s.getName() == &quot;VIP&quot; &amp;&amp; r.getColumn() == 26 &amp;&amp; r.getValue() == &quot;Yes&quot;) {
      var row = r.getRow();
      var numColumns = &quot;25&quot;
      var targetSheet = ss.getSheetByName(&quot;Archive - VIP&quot;);
      var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
      s.getRange(row, 1, 1, numColumns).moveTo(target);
      s.deleteRow(row);
    }  
   if(s.getName() == &quot;Service&quot; &amp;&amp; r.getColumn() == 26 &amp;&amp; r.getValue() == &quot;Yes&quot;) {
      var row = r.getRow();
      var numColumns = &quot;25&quot;
      var targetSheet = ss.getSheetByName(&quot;Archive - Service&quot;);
      var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
      s.getRange(row, 1, 1, numColumns).moveTo(target);
      s.deleteRow(row);
    }
  }
  </code></pre>
  <p>Thanks in advance!</p>