简体   繁体   中英

How do I run Google Sheets App Script on all sheets (tabs) in a Google Sheet?

I am trying to make the following script run on all the sheets(tabs) EXCEPT for one in my Google Sheet. I need some help. Thanks.

function myFunction() {

var sheet = SpreadsheetApp.getActiveSheet();

var cell = sheet.getRange("B4");

var refresh = parseInt(cell.getValue().toString()); var increment = refresh + 1;

cell.setValue(increment); }

Assuming that your script gives you what you expect

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  ss.getSheets().forEach(function (sheet){
    var cell = sheet.getRange("B4");
    var refresh = parseInt(cell.getValue().toString()); 
    var increment = refresh + 1;
    cell.setValue(increment);
  })
}

Edit by Cooper: Perehaps something like this:

function myFunction() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  const exclA = ['Sheet1','Sheet2'];//excluded sheets
  ss.getSheets().filter(sh => {!~exclA.indexOf(sh.getName())}).forEach(function (sheet){
    var cell = sheet.getRange("B4");
    var refresh = parseInt(cell.getValue().toString()); 
    var increment = refresh + 1;
    cell.setValue(increment);
  })
}

bitwise not

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM