Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get calling cell address in Google Apps Script custom function

I want to use the cell address (of the cell the formula is in) in a custom formula. e.g. In my sheet I have a formula in cell C7: =fSomeFormula() In my code I need something like

function fSomeFormula(){
  var a = source.getA1Notation();
  var b = source.getRow();
  var c = source.getColumn();
  return [a,b,c]; //returns ["C7",7,3]
};

Is this possible? Thanks in advance..

like image 1000
Arvid Avatar asked Oct 28 '25 20:10

Arvid


1 Answers

This is not documented, but calling getActiveCell() or getCurrentCell() in custom functions returns the Range of the cell calling the function, not the "active" cell or "the cell that has focus in the Google Sheets UI, and is highlighted by a dark border".

So the answer is,

function currentCell() {
  const cell = SpreadsheetApp.getActiveSheet().getCurrentCell();
  return `[${cell.getA1Notation()}, ${cell.getRow()}, ${cell.getColumn()}]`;
}

get current cell address in Google Apps Script custom function

like image 117
Dan Dascalescu Avatar answered Oct 31 '25 12:10

Dan Dascalescu



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!