I have a summary sheet called Summary. I then have multiple tabs that apply to people - these are named after them eg John Smith, Will Jones, Sally Smith... I want to sum or count the same cell in each of named tabs - how do I do this automatically?
What you can actually do is traverse all the sheets and them just sum them up. The sample below shows how to sum all cell 'A1' in all sheets.
function sumCells() {
const cellLocation = "A1";
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheets = ss.getSheets().filter(function (sheet) {
return sheet.getSheetName() != "Summary";
}); // added filter to exclude Summary sheet from the calculation
var sum = 0;
var sheetName, cell, value;
sheets.forEach((sheet) => {
sheetName = sheet.getName();
cell = sheet.getRange(cellLocation)
value = cell.getValue();
sum += parseFloat(value); // if has decimal
// sum += parseInt(value); // if has whole numbers (no decimal)
})
Logger.log(sum);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.