I have the following script.
I have a spreadsheet with 10 worksheets and 15 users logging in and modifying it.
There is no active sheet when your function runs as a trigger. The active sheet is applicable only when a user has the spreadsheet open. Modify your script to use getSheetByName
and everything should work fine.
If you want this to work on multiple sheets, just call this function from another function..
function shellFunction(){
var sheets = ['sheet1','sheet2',etc];
for (var s in sheets){
toTrigger(sheets[s]);
}
}
And change your toTrigger
function to receive the sheet name as argument.
function toTrigger(sheetName){
var sh = SpreadsheetApp.openById(ID OF SPREADSHEET).getSheetByName(sheetName);
/* Your regular code */
}