Really confused here – this script works in one document, but not in another. I’ve tested out altering tab names, using an array vs. a bunch of if statements, really not sure where to go here.
Ultimately, all I want to do is add a row above row 30 on every tab in my document minus a few:
function insertRow() {
// Retrieve the spreadsheet
const ss = SpreadsheetApp.getActiveSpreadsheet();
var allsheets = ss.getSheets();
var exclude = ["Sheet2", "Sheet5"];
for(var s in allsheets){
var sheet = allsheets[s];
// Stop iteration execution if the condition is meet.
if(exclude.indexOf(sheet.getName())==-1) continue;
sheets[i].insertRowBefore(row);
}
}
>Solution :
Insert a row above row 30
function insertRowBefore30() {
const ss = SpreadsheetApp.getActive();
const shts = ss.getSheets();
var exclude = ["Sheet2", "Sheet5"];
shts.filter(sh => !~exlude.indexOf(sh.getName())).forEach(sh => sh.insertRowBefore(30));
}