Google Sheets: sum cell on across all tabs

Viewed 21

I am trying to create a script that will sum all values in a given cells (for example G1) on all and future tabs. I have come across sum3D (answer from Mike Steelson - link below) which seems to do the trick but it does not automatically update. You have to delete the text and re-type the formula. I would like for the cell to update whenever the data changes on the tabs.

Thank you in advance for your help. Below is a link to the original creator I believe. https://stackoverflow.com/a/73102896/19997363

function sum3D() {
  const ss = SpreadsheetApp.getActiveSpreadsheet()
  var shs = ss.getSheets();
  var rng = ss.getActiveSheet().getActiveCell().getA1Notation()
  var sh1 = ss.getSheetByName('b').getIndex()
  var sh2 = ss.getSheetByName('e').getIndex()
  var result = 0
  for (var i = sh1; i < sh2; i++) {
    result += shs[i].getRange(rng).getValue()
  }
  return result
}
0 Answers
Related