'Looping a function over different sheets in google scripts
so I have function lets call that XXXX . That function works over the course of one sheet only, trying to get it to work over all sheets as long as the sheet's name isn't "YYYY" or the sheet name doesn't include "ZZZZ" . What I have below runs our function (XXXX) on the first sheet then activates the last without running it over the sheets between the first and the last. Any help would be appreciated.
function run_XXXX_for_all_tabs(){
var spreadsheet = SpreadsheetApp.getActive();
var allSheets =spreadsheet.getSheets();
allSheets.forEach(function(sheet){
if(sheet.getSheetName() !== "YYYY" && sheet.getSheetName().search("ZZZZ") < 0){
sheet.activate();
XXXX();
}
})
}
Solution 1:[1]
Try this:
function myFunction() {
SpreadsheetApp.getActiveSpreadsheet()
.getSheets()
.filter(i => i.getName() !== `YYYY` && !i.getName().includes(`ZZZZ`))
.forEach(i => {
i.activate()
XXXX()
})
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


