Get the row/column ID using office script in an excel report
Getting the row and/or the column ID is important because it will allow to define the range to perform different actions. The “getRowIndex” and “getColumnIndex“ functions allow to do it but remember that the script defines row 1 = row 0 and column 1 (which is A) = column 0 so in the code below, I will add “+ 1” after the function. For the column, I also add a code line to get the letter so just choose which one you need, the ID or the letter.
Row ID | Column ID |
When I use the script ?
To find the column or the row ID based on value to be used for a range.
How to create the script ?
Read How to create, edit and select an Office Script in an excel report
How to create the button to associate it with the script ?
Read How to create a button and associated it to an Office Script in an excel report
How is/are the script(s) ?
Copy the code below and paste it into your script. You will see my comments in green if exist so follow the help to adapt to your need.
For row ID:
function main(workbook: ExcelScript.Workbook) { // change column range D2:D5 by yours // change oracle by yours // remove + 1 to get ID as defined by script let rowid = workbook.getActiveWorksheet().getRange("D2:D5").find("oracle", { completeMatch: false, matchCase: false, }).getRowIndex() + 1; console.log(rowid) }
For column ID:
function main(workbook: ExcelScript.Workbook) { // change row range 3:3 by yours // change close by yours // remove + 1 to get ID as defined by script let columnid = workbook.getActiveWorksheet().getRange("3:3").find("close", { completeMatch: false, matchCase: false, }).getColumnIndex() + 1; // split("3") corresponds to row 3 let columnletter = workbook.getActiveWorksheet().getRange("3:3").find("close", { completeMatch: false, matchCase: false, }).getAddress().split("3")[0]; console.log(columnid) console.log(columnletter) }
Interesting Topics
-
Be successfully certified ITIL 4 Managing Professional
Study, study and study, I couldn’t be successfully certified without studying it, if you are interested...
-
Be successfully certified ITIL 4 Strategic Leader
With my ITIL 4 Managing Professional certification (ITIL MP) in the pocket, it was time to go for the...
-
Hide visual and change background color based on selection
Some small tricks to customize the background colour of a text box...
-
Stacked and clustered column chart or double stacked column chart
In excel, I use a lot the combination of clustered and stacked chart...