Know the letter/number of a column using a macro in an excel report
This is a simple macro to know the letter of a column based on its number, for instance, I want to know the letter of the column 27.And vice versa, for instance, I want to know the number of the column AA. Usually, I combine with other macros, for example, I want to copy the cells of the last column but this last column is always updated with new data.
When I use the macro ?
To know the letter or the number particularly when the column has a high number (for instance 76, what is the corresponding letter ?) or letter (for instance DZ, what is the corresponding number ?).
How to create the macro ?
Read How to create, edit, hide and select a macro in an excel report
How to create the button to associate it with the macro ?
Read How to create a button and associated it to a macro in an excel report
How is/are the macro(s) ?
Copy the code below and paste it into your macro. You will see my comments in green if exist so follow the help to adapt to your need.
To know the letter of a column:
Sub test() Dim ColumnNumber As Long Dim ColumnLetter As String ' change 7 by a number ColumnNumber = 7 ColumnLetter = Split(Cells(1, ColumnNumber).Address, "$")(1) MsgBox "Column " & ColumnNumber & " = Column " & ColumnLetter End Sub
To know the number of a column:
Sub test() Dim ColumnNumber As Long Dim ColumnLetter As String ' change G by a letter ColumnLetter = "G" ColumnNumber = Range(ColumnLetter & 1).Column MsgBox "Column " & ColumnLetter & " = Column " & ColumnNumber End Sub
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...