I found a script which I really need (link):
function getTotalSum(cell) {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var sum = 0;
for (var i = 0; i < sheets.length ; i++ ) {
var sheet = sheets[i];
var val = sheet.getRange(cell).getValue();
if (typeof(val) == 'number') {
sum += val;
}
}
return sum;
}
but it gives an error (Exceeded maximum execution time) generally.
How can I solve this error?
Best Answer
I have tried the following custom function successfully up to 170 sheets:
Going beyond the 170, problems ariase:![enter image description here](https://i.stack.imgur.com/NcD72.png)
Therefore I created the code below that can be used for at least 750 sheets (but not to be used as a custom function).
Code
Explained
The custom function isn't really meant to be used this extensively. Oddly, the custom function runs well within the 5 minutes of execution time for the 170 sheets (30s). The usage of
.getDataRange().getValues()
is slightly advantageous over the.getValue()
(appr. 30s for 750 sheets).Example
I've created an example file for you: 750 sheets
Create a copy and look for the extra pieces of code I added.