Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sheets is not defined Issue?

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);
  }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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));
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading