Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
How do I copy only the visible rows from one tab to another in Google Sheets?

I have an input tab with 13 columns of data. I used the filter from Google Sheets to restrain the data and I want only the filtered data to be put in an output tab.

I tried using this Google Apps Script code for that, however it does not work as intended.

function showResults() {
  var sheet = SpreadsheetApp.getActiveSheet();  
  var data = [];

  for (var i = 1; i < sheet.getLastRow(); i++) {
    if(!sheet.isRowHiddenByFilter(i)) {
      var row_data = sheet.getRange("A" + i + ":M" + i).getValues();
      console.log(row_data);
      data.push(row_data);
    }
  }
  
  sheet.getRange('Results!A1:M' + (data.length + 1)).setValues(data);
}

The problem I noticed in the logs is that it only goes through the first row of the filtered data before exceeding the maximum execution time.

Any help is appreciated, especially if it's a Google Sheets feature I didn't know about and not necessarily the code.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hi you must clone your sheet and use cloned object for fix your problem like this :

function showResults() {
  var sheet = SpreadsheetApp.getActiveSheet();  
  var data = [];

  for (var i = 1; i < sheet.getLastRow(); i++) {
     let cache = JSON.parse(JSON.stringify(sheet ))
    if(!sheet.isRowHiddenByFilter(i)) {
      var row_data = cache.getRange("A" + i + ":M" + i).getValues();
      console.log(row_data);
      data.push(row_data);
    }
  }
  
  sheet.getRange('Results!A1:M' + (data.length + 1)).setValues(data);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!