Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda