I want to pimp my private household google sheet with some functions. Therefore I wrote a function with a for loop to iterate over the rows 1-1000 to calculate how much money I spent. The function works and it calculates the numbers correctly. Everything is fine, but...
My Problem: After I added some values I have to reload the whole page to make the functions run again.
What I want: I would like to write a function that triggers a re-run of all functions in my sheet. Therefore I created a button that I can click.
What I tried:
SpreadsheetApp.flush();
as described here but it did not work. There was some processing but no value changed.
Edit 31.10.2017
This is the code I wrote. I would like to execute it everytime I edit the spreadsheet.
function sumValues(startRow, startColumn) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName("MySheet");
var range = sheet.getRange(startRow, startColumn, 1000);
var data = range.getValues();
var costs = calculate(data);
return costs;
}
function calculate(data) {
var cost = 0;
var size = data.length;
for(var i=0; i<size; i=i+1) {
var current = data[i][0];
if(typeof current == 'number') {
cost = cost + current;
}
}
return cost;
}