user2411383
user2411383

Reputation: 11

Google Sheets getActiveRange on change

I have a function starting off as such

function onEdit2(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  // Returns the active cell
  var activeRange = sheet.getActiveRange();

  Logger.log(activeRange.getA1Notation());

I have this function triggered 'on change' in a spreadsheet (it was originally on edit, hence the name, but that isn't triggered by changing background color, which is kinda critical to what I'm doing with this).

This always writes A1 to the logger, no matter what part of the spreadsheet I have selected, and it does the same thing with getActiveCell in place of getActiveRange.

Is there any way to get the selected range when a script runs?

Upvotes: 1

Views: 1708

Answers (1)

Mogsdad
Mogsdad

Reputation: 45710

This is a serious drawback with this new trigger type. There has already been an issue raised about it:

Issue 2751: SpreadSheet onChange() trigger

Visit & star the issue to receive updates. It would be helpful to add your own observations as well, since the original issue has been entered as an enhancement request, but the fact that the trigger doesn't know the changed range is bug-flavoured.

Upvotes: 2

Related Questions