Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!