0
votes

Need to get the rownumbers for the changed rows in Google Spreadsheet.

The spreadsheet got a lot of rows and calculate a SUM depending on a spefific column. When I delete the values in a column, a new SUM must be calculated. This works great when I change 1 one row, but often I select the column for more that one rows and delete the content. My expectation was that the onEdit event will be fired more than once.

After that I hoped that the getRange function gives me the rownumbers, but it's not.

function onEdit()
{
  var as = SpreadsheetApp.getActiveSheet();

  var edditRow = SpreadsheetApp.getActiveRange().getRow();
  var edditColumn = SpreadsheetApp.getActiveRange().getColumn();  

  LKfunctions.RecalcalculateTimes(edditRow, edditColumn);
}

Hopefully some good suggestion how to solve this problem.

1

1 Answers

0
votes

.getRow() returns just the first row number of a range.

.getNumRows() returns the number of rows in a range.

I suggest you add them together and use a loop to do your recalculation. Something like this:

    function onEdit()
{
  var as = SpreadsheetApp.getActiveSheet();
  var r = as.getActiveRange();
  var numRows = r.getNumRows();
  var edditRow = r.getRow();
  var edditColumn = r.getColumn();
  for (var i=edditRow; i<edditRow+numRows; ++i) {
    LKfunctions.RecalcalculateTimes(i, edditColumn);
    Logger.log('Editted row ' + i);
  }
}