Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script take a list of sheets by ID and will iterate through each one. I found this helpful when needing to apply changes to a large number of sheets. If you set it up to run every hour or fifteen minutes it can change as many as you need. If the script times out, it will begin where it left off the next time it runs.
function changeAll() {
//Insert the id of the sheet that contains all the spreadsheets by id
var msheet = SpreadsheetApp.openById('---').getSheetByName("Sheet Ids");
var mdata = msheet.getRange('C:C').getValues();
//m-varname is the master data
var startd = new Date();
var diff = 0;
//Start keeps track of what row you are on incase the script times out.
var start = Number(PropertiesService.getScriptProperties().getProperty("START"));
Logger.log(start);
Logger.log("DATA LENGTH " + mdata.length);
for(var i = start; i < mdata.length && diff < 280; i++){
//Get spreadsheet from list
var id = mdata[i][0];
var spread = SpreadsheetApp.openById(id);
//MAKE CHANGES TO SHEET HERE *****************************************************************
//END CHANGE AREA ****************************************************************************
//Change time and counter for next run
PropertiesService.getScriptProperties().setProperty("START", i);
var now = new Date();
var difdate = (now.getTime() - startd.getTime()) * 0.001;
diff = difdate;
Logger.log("DIFF: " + diff);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.