2
votes

I am trying to figure out how to get the A1 Notation of a Cell calling a Custom Function.

I found this but this is for active cell. https://webapps.stackexchange.com/questions/54414/in-google-script-get-the-spreadsheet-cell-calling-a-custom-function

Essentially if I want Cell A5 to Call =TEST(). I want the function to return the text value A5.

I want to use this as a cache identifier for an API Call.

1
Have you tested it? It'll work fine.TheMaster

1 Answers

8
votes

There are subtle differences in different range returning method names- active,current,selection:

The term "active range" refers to the range that a user has selected in the active sheet, but in a custom function it refers to the cell being "active"ly recalculated.

The current cell is the cell that has focus in the Google Sheets UI, and is highlighted by a dark border.

A selection is the set of cells the user has highlighted in the sheet, which can be non-adjacent ranges. One cell in the selection is the current cell, where the user's current focus is.

The first two are still range objects,while the latter is not.

I want the function to return the text value A5.

Without Custom Functions,We can use:

=ADDRESS(ROW(),COLUMN())

With Custom function,We can use:

function test() { 
 return SpreadsheetApp.getActiveRange().getA1Notation(); 
}