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

Josanon

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')
}
Mike Steelson

Try

function myFunction() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  ss.getSheets().forEach(function(dataSht){
    dataSht.insertRows(2,1)
    dataSht.getRange("A2:B2").setFormula('=A3:B3')
  })
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I search for data in Google Sheets using multiple keywords?

How can I improve my script to make it faster when search from multiple sheets?

Google Script to watch multiple sheets: how do I simplify this script?

How can I correlate rows in two sheets in Google Sheets?

How can I only run a calculation in Google Sheets, if the cell is not empty?

How can I filter my rows by background color in Google Sheets?

How do I make my Sheets script create multiple events in my Calendar from a given range?

How do I run a Google Apps script on all sheets in my spreadsheet file?

How can I make this google sheets script code shorter/faster?

How can I filter multiple tabs/sheets in google sheet

How can I automate COUNTIF formulas across multiple Google sheets?

How can I combine multiple columns into one column in Google Sheets?

How can I use RegEx to find and replace over multiple columns in Google Sheets using App Script?

How can I iterate through multiple excel sheets to apply simple data cleaning to all sheets?

Google Sheets run the script in all sheets

In google sheets how do I make a list of names based on other multiple other columns data?

Google Sheets Hide Rows Across Multiple Sheets

Google Apps Script - how to applies this code for multiple sheets in google sheets

How to delete same rows or ranges across multiple sheets in Google Sheets?

I need to remove the header rows(?) from my filtered and copied data in Google Sheets

Can i use an external program to run custom scripts in google sheets?

How can run the following code on multiple Excel sheets?

How can Google sheets loop multiple cells through sheets?

I need help calling new data from a Google Form sheet into multiple other sheets automatically

Can I export my data to a Google Doc from Google Sheets using Apps Script?

How do I get 5 rows from the end of my sheet in Google Sheets using Apps Script?

Can I make a cyclic string in google sheets?

How do I transform a single row of repeating data instances into multiple rows, of one instance per row? (Google Sheets)

How can i run this excel script on all sheets ? Remove all hyperlinks in entire workbook

TOP Ranking

HotTag

Archive