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..
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()}]`;
}

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