Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Spreadsheet cell calling a custom function

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.

like image 909
jef2904 Avatar asked Sep 03 '26 05:09

jef2904


1 Answers

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. To reiterate, getActiveRange()

in a custom function it refers to the cell being "active"ly recalculated.


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(); 
}
like image 53
TheMaster Avatar answered Sep 04 '26 20:09

TheMaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!