0
votes

I have this function which takes sum of a particular column from other sheet.

function FindEffort(sheetNames,columnName) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets=sheetNames.split(',');
  var sum=0;
  for(var s=0;s<sheets.length;s++){
  var sheet=ss.getSheetByName(sheets[s]);
  var data = sheet.getDataRange().getValues();
  var col = data[0].indexOf(columnName);
  if (col != -1) {
    for (var r=1; r<data.length; r++) {
      var row = data[r];
      if(row!=undefined){
        if(row[col]!=null);
        sum+=Number(row[col]);
      }
    }
  }
  }

  return sum;
}

I am calling this function in sheet 1 and fetch sum of a column from sheet 2.But data only load first time.For example if I add value in a column of sheet 2 which's sum get my formula in sheet 1.It does not reflect the changes.

1

1 Answers

0
votes

You'll have to write an onEdit trigger that will update the cell value in sheet 1 when the columns in sheet 2 are updated.