Home > database >  How do you find the cell number of a cell you are running a function in AppScript?
How do you find the cell number of a cell you are running a function in AppScript?

Time:08-31

I am currently making a function in appscript that can be called from a cell in Spreadsheets. I want to be able to get that cell's number in order to use it, say if the formula is running in cell G3, I want to find that cell and use it in my script.

CodePudding user response:

I played around with this once and I seem to recall find that getActiveCell() seems to work. But I am confident that you will find a condition where it does not work

function WHEREAMI(a) {
  let c = SpreadsheetApp.getActiveCell().getA1Notation();
  Logger.log(c);
  return c;
}

You don't necessarily need a parameter but if you wish one then adding a cell reference allow you force them to change

CodePudding user response:

You can get the A1 notation of the active cell:

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

and then call it like that:

enter image description here

  • Related