0

I try to refuse to believe that there is no Class Range method to retrieve the row or column index for a cell given. But I couldn't find anything searching for this other than the below-refered link.

var activeSheet = SpreadsheetApp.getActiveSheet();
var cellPositionToConvert = activeSheet.getRange("B3")
// cellPositionToConvert ".GETCOLUMN()" ".GETROW()"

Return I'm looking for:

[2, 3]

I could only find this "famous" self-constructed function to deal with that. I would be more than kneen to know and discuss, if there are any other ways to convert this a1Notation.

stack overflow post-link

BenjaminK
  • 653
  • 1
  • 9
  • 26
  • 1
    There is getRow() and getColumn() – TheMaster May 04 '20 at 13:46
  • @TheMaster `cellPositionToConvert.getColumn()` only returns `range` so nothing I can work with (like for example an int) – BenjaminK May 04 '20 at 13:51
  • 1
    That would surprise me. `cellPositionToConvert.getColumn()` is expected to return correctly the column number as an int - provided `cellPositionToConvert` correctly contians an instance of a `range`. – ziganotschka May 04 '20 at 14:16
  • You're completely right, I made the mistake somewhere else and ended up reading the wrong `Looger` data. I'll delete this post as my first try `.getColumn()` is now working correctly. – BenjaminK May 04 '20 at 14:45
  • Should I delete the question or keep it? What do you think? – BenjaminK May 04 '20 at 14:54

1 Answers1

0

Documentation Get Column

Documentation Get Row

// Get active Sheet
var activeSheet = SpreadsheetApp.getActiveSheet();

// Get cell by a1notation
var cellPositionToConvert = activeSheet.getRange("B3");

// Get row and column for choosen cell and store them in Array
var cellIndex = [activeSheet.getRow(), activeSheet.getColumn()];
BenjaminK
  • 653
  • 1
  • 9
  • 26