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

261
Visualizações
How to get the last 1000 rows dynamically and sort them using GAS?

I'm trying to get this to sort only the last 1000 rows, dynamically. This is the code I'm using:

function sort(e){
const formRespSheet = e.source.getSheetByName('Form Responses 1');
let lr = formRespSheet.getLastRow()-1;
let firstRow = 2
 if (lr > 1000) {
   firstRow = lr - 1000;
 }
 Logger.log('First Row: ' + firstRow)
 Logger.log('Last Row: ' + lr)
 formRespSheet.getRange(firstRow, 1, lr, 16).sort(14);
}

It gives me the correct firstRow and lr, but it also throws The coordinates of the range are outside the dimensions of the sheet, besides running forever (15 sec).

Could anyone help me find the flaw here (besides myself)?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The signature of getRange uses numRows and numColumns, not lastRow and lastColumn.

Because you start selecting at row 2 it tries to get a range one row beyond what the spreadsheet has.

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