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

145
Visualizações
How can I make my script run on multiple sheets on Google Sheets ? I'm inserting rows with data and need it to run on multiple sheets

I'm writing a script that inserts a row below row 1 of each sheet and includes some data in that row. It works for the first sheet, but I need it to run for multiple sheets. Each sheet is a business manager's name (Brian, for example), and it would be helpful to have this run for all sheets. I have tried several methods from previous similar questions but have not gotten anything to work. The code is below.

function myFunction() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var dataSht = ss.getSheetByName("Brian");
  var lastRow = dataSht.insertRows(2,1)
  var dataRng = dataSht.getRange("A2:D2").getValues();
  dataSht.getRange("A2:B2").setFormula('=A3:B3')
}
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

If you don't wish to use all sheets

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const incl = ["Brian", "others"]
  ss.getSheets().filter(s => ~incl.indexOf(s.getName())).forEach(sh => {
    sh.insertRows(2, 1)
    sh.getRange("A2:B2").setFormula('=A3:B3')
  })
}
about 4 years ago · Santiago Trujillo Relatório

0

Try

function myFunction() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  ss.getSheets().forEach(function(dataSht){
    dataSht.insertRows(2,1)
    dataSht.getRange("A2:B2").setFormula('=A3:B3')
  })
}
about 4 years ago · Santiago Trujillo 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