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

226
Visualizações
How to delete sheets based on a name criteria using Google Apps Script?

I've been trying to delete existing sheets whose names match a criteria, but I keep running into the error below and I can't find out why.

The code I'm running:

const SS = SpreadsheetApp.getActiveSpreadsheet();
const allSheets = SS.getSheets();
const category = 'Block-A';
const newSheetName = 'BOQ ' + category;

for (let a = 0; a < allSheets.length; a++) {
  let existingSheetName = allSheets[a].getName();
  if (existingSheetName == newSheetName) {
    SS.deleteSheet(allSheets[a]);
  }
}

The error: Sheet xxxxxxxxxx not found

Appreciate your help.

Antonio

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

0

After reading through the comments on the question, this is what has worked for me:

First, make sure that the sheet names are listed. In my case, I got a column clientCategories whose each value would become a sheet name:

let sheetsToDel = [];
for (let a = 0; a < clientCategories.length; a++) {
  sheetsToDel.push('BOQ ' + clientCategories[a])
}

Then, I'd go through all the sheets and delete them:

for (let a = 0; a < allSheets.length; a++) {
  const sheetName = allSheets[a].getName()
  for (let r = 0; r < sheetsToDel.length; r++) {
    if (sheetName == sheetsToDel[r]) {
      SS.deleteSheet(allSheets[a]);
    }
  }
}

There may be many better ways to it, but this is what I got.

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