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

118
Visualizações
How to make automatically delete rows with multiple sheet in google script

How to make automatically delete rows with multiple sheet in google script based on trigger, I've used this script and it worked, but I want this script to be able to use two or more tab sheets at once while the current script only uses one tab sheet. how to use more than one tab sheet in getSheetByName? Can anyone help me? because every time I ask here no one responds, this is my third question, that the previous two no one helped answer. is there something wrong i don't know.

function acraCleanup() { 
  var SPREADSHEET_KEY = "AABVGGHJGFGDFG4GFD65GHDF56HGFHG53";

// Replace with your spreadsheet Key,

//you can find this by trying to share the Spread sheet

// and getting the key between the "=" and the "&" 

  var SHEET_NAME = "Sheet 1"; //Sheet 1 unless you changed the sheet name 
  var rowsToKeep = 1000; //Will keep bottom 1000 Rows 
  var sheet  = SpreadsheetApp.openById(SPREADSHEET_KEY).getSheetByName(SHEET_NAME); 
  var rows = sheet.getLastRow(); 
  var numToDelete = rows – rowsToKeep  -1; 
  if (numToDelete > 0) sheet.deleteRows(2, numToDelete); 
}

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

0

Try

function acraCleanup() { 
  var SPREADSHEET_KEY = "AABVGGHJGFGDFG4GFD65GHDF56HGFHG53";
  var rowsToKeep = 1000; //Will keep bottom 1000 Rows 
  const list = ['SheetX','SheetY'];
  var ss  = SpreadsheetApp.openById(SPREADSHEET_KEY)
  ss.getSheets().filter(sh => list.indexOf(sh.getName()) != -1).forEach(function (sheet){
    var rows = sheet.getLastRow(); 
    var numToDelete = rows - rowsToKeep  - 1; 
    if (numToDelete > 0) sheet.deleteRows(2, numToDelete);
  })
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Keep 1000 rows below the header

function acraCleanup() { 
  const list = ['Sheet1','Sheet2'];
  var ss  = SpreadsheetApp.openById("ssid")
  ss.getSheets().filter(sh => ~list.indexOf(sh.getName())).forEach(sheet => {
    let rows = sheet.getLastRow(); 
    if(rows > 1001) {
      sheet.deleteRows(2 ,rows - 1001)
    }
  });
}
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