19

Is there a way to get the identification (i.e. A1 notation) of a selected cell or range in Google Sheets?

Something like:

=SELECTION(['Sheet1']) -> "D6"
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
  • 2
    use getActiveRange() you can read about it [here](https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getactiverange) – Akshin Jalilov Jun 11 '15 at 11:31
  • Do you mean as a function in the spreadsheet, or by use of [tag:google-apps-script]? – Mogsdad Jun 13 '15 at 03:58
  • I meant a spreadsheet function. I wanted to bring some interactivity to the sheet, so it would react to cell selection change. (Range not included). Last time I checked, that's was not possible. – Ondra Žižka Oct 14 '18 at 18:09

1 Answers1

23

This custom function will get the selection at the time you update the cell with the function. But it will not update as the selection changes.

Henrique provides a good explanation of why custom functions like this don't update in Google Apps - script to summarise data not updating.

/**
 * A function that gets the current selection, in A1Notation.
 *
 * @customfunction
 */
function SELECTED_RANGE() {
  return SpreadsheetApp.getActive().getActiveRange().getA1Notation();
}
Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275