title: Delete filtered rows in google sheets script (10000+ rows)
body: <p>I need help deleting the filtered row in a sheet without timing out. There are over 10,000 rows in the sheet so running a for loop with DeleteRow() is timing out.</p>
  <p>The larger goal of the project is to basically archive data from the main sheet to an archive sheet automatically if the date is more than 31 days ago.</p>
  <p>This is the current code I currently have to do this but the loop is working really slow with as much data as I have in the sheets. If there are any other major performance improvements feel free to make those suggestions as well. This is my first real time working with google app scripts</p>
  <pre><code>  var ss = SpreadsheetApp.getActiveSpreadsheet();
    var copy_sheet = ss.getSheetByName(&quot;upload&quot;);
    var paste_sheet = ss.getSheetByName(&quot;archive&quot;);
    const day = 24 * 60 * 60 * 1000;
    var date = new Date();
    var remove_before_date = new Date()
    remove_before_date.setDate(date.getDate()-31);
  
    var prev_filter = copy_sheet.getFilter();
    if (prev_filter !== null) {
      prev_filter.remove();
      return;
    }
    //create filter
    var range = copy_sheet.getRange(&quot;A:I&quot;);
  
    var filter = range.createFilter();
  
    var Filter_Criteria = SpreadsheetApp.newFilterCriteria().whenDateBefore(remove_before_date);
  
    var add_filter = filter.setColumnFilterCriteria(1,Filter_Criteria);
  
    //copy and paste
    var range = copy_sheet.getDataRange().offset(2,0);
    var last_row_archive = paste_sheet.getDataRange().getNumRows();
    var last_row_upload = copy_sheet.getDataRange().getNumRows();
  
    paste_sheet.insertRowAfter(last_row_archive)
    range.copyTo(paste_sheet.getRange(last_row_archive+1,1));
    
  
    //delete from upload
    for (var i = last_row_upload; i &gt; 2; i--) {
      if (!copy_sheet.isRowHiddenByFilter(i)) {
        copy_sheet.deleteRow(i);
      }
  }
  
    //remove filters
    filter.remove();
  
  }```
  </code></pre>