Automatic Recalculation of Custom Function on Spreadsheet Part 1
In this report, I would like to introduce a workaround for automatically recalculating custom functions on Spreadsheet.
1. Situation
The sample situation is below. This is a sample situation for this document.
- There are 3 sheets with “sheet1”, “sheet2” and “sheet3” of sheet name in a Spreadsheet.
- Calculate the summation of values of “A1” of each sheet using a custom function.
- Sample script of the custom function is as follows.
function myFunction(e) {
var r = 0;
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i in sheets) {
r += sheets[i].getRange(e).getValue();
}
return r;
}
2. Workaround for recalculating
When =myFunction("A1") is put in a cell, the custom function sums each “A1” of “sheet1”, “sheet2” and “sheet3”. But in this case, when “A1” of one of 3 sheets is changed, the custom function is not recalculated.