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')
}
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.
Comments