Excel VBA Column Number to Name example macro will convert column number to Excel alphabetic Letter character column name. Most of the time while automating many tasks using Excel VBA, it may be required. Please find the following details about conversion of number to name. You can also say column number to column string. Or number to letter using Excel VBA. Please find the following different strategic functions to get column number to column name.
Column Number to Column Name: Easiest Approach by Replacing a Cell Address
Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are referring a cell address.
'Easiest approach by Replacing a Cell address Function fnColumnToLetter_CellAdressReplace(ByVal ColumnNumber As Integer) fnColumnToLetter_CellAdressReplace = Replace(Replace(Cells(1, ColumnNumber).Address, "1", ""), "$", "") End Function
Column Number to Column Name: Example and Output
Please find the below example. It will show you how to get column name from column number using Excel VBA. In the below example ‘fnColumnToLetter_CellAdressReplace’ is a function name, which is written above. And “105” represents the row number of ‘fnColumnToLetter_CellAdressReplace’ function parameter.
Sub sbNumerToLetter_ExampleMacro() MsgBox "Column Name is : " & fnColumnToLetter_CellAdressReplace(105) End Sub
Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.
Column Number to Column Name: By Referring Excel Range and Using SPLIT Function
Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are referring Excel range and ‘Split’ function.
'By refering Excel Range and using SPLIT function Function fnColumnToLetter_Split(ByVal intColumnNumber As Integer) fnColumnToLetter_Split = Split(Cells(1, intColumnNumber).Address, "$")(1) End Function
Column Number to Column Name: Example and Output
Please find the below example. It will show you how to get column name from column number using Excel VBA. In the below example ‘fnColumnToLetter_Split’ is a function name, which is written above. And “15” represents the row number of ‘fnColumnToLetter_Split’ function parameter.
Sub sbNumerToLetter_ExampleMacro1() MsgBox "Column Name is : " & fnColumnToLetter_Split(15) End Sub
Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.
Column Number to Column Name: Using Chr Function and Do While loop
Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are referring a ‘Chr’ function and Do While loop.
'Using chr function and Do while loop Function fnColumnToLetter_DoLoop(ByVal intColumnNumber As Integer) As String Dim bColDenom As Byte fnColumnToLetter_DoLoop = "" Do bColDenom = ((intColumnNumber - 1) Mod 26) fnColumnToLetter_DoLoop = Chr(bColDenom + 65) & fnColumnToLetter_DoLoop intColumnNumber = (intColumnNumber - bColDenom) 26 Loop While intColumnNumber > 0 End Function
Column Number to Column Name: Example and Output
Please find the below example. It will show you how to get column name from column number using Excel VBA. In the below example ‘fnColumnToLetter_DoLoop’ is a function name, which is written above. And “10” represents the row number of ‘fnColumnToLetter_DoLoop’ function parameter.
Sub sbNumerToLetter_ExampleMacro2() MsgBox "Column Name is : " & fnColumnToLetter_DoLoop(10) End Sub
Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.
Column Number to Column Name: Using Recursive Approach
Please find the following details about conversion from Column Number to Column Name in Excel VBA. Here we are using recursive approach.
'Using Recursive Approach Function fnColumnToLetter_Rec(intColumnNumber As Integer) As String If intColumnNumber > 26 Then fnColumnToLetter_Rec = fnColumnToLetter_Rec((intColumnNumber - ((intColumnNumber - 1) Mod 26)) / 26) + Chr((intColumnNumber - 1) Mod 26 + 65) Else fnColumnToLetter_Rec = Chr(intColumnNumber + 64) End If End Function
Column Number to Column Name: Example and Output
Here is the example macro procedure. It will show you how to get column name from column number using Excel VBA. In the below example “fnColumnToLetter_Rec” is a function name, which is written above. And “4” represents the row number of “fnColumnToLetter_Rec” function parameter.
Sub sbNumerToLetter_ExampleMacro3() MsgBox "Column Name is : " & fnColumnToLetter_Rec(4) End Sub
Output: Press ‘F5’ or click on Run button to run the above procedure. Please find the following output, which is shown in the following screen shot.
More about Column Name to Column Number Conversion
Here is the link to more about how to convert column name to column number using VBA in Excel.
‘=IF(MID(ADDRESS(3,COLUMN(),,,),3,1)=”$”,MID(ADDRESS(3,COLUMN(),,,),2,1),MID(ADDRESS(3,COLUMN(),,,),2,2))
Hi ,
I dont know excel much , but i tried to solve this by using simple formulas.
hope you find this OK.
Thanks
Arun
Hi arun Sharma,
I do not understand your formula and could not get it to work. Can you explain it?
I have tried to explain a few VBA Codes here:
http://www.excelforum.com/tips-and-tutorials/1108643-vba-column-letter-from-column-number-explained.html
Alan
Another alternative: Application.ConvertFormula(Formula,FromReferenceStyle,ToReferenceStyle)
For example, Application.ConvertFormula(“C215”,xlR1C1,xlA1) returns:$HG:$HG and
Application.ConvertFormula(“$HG:$HG”,xla1,xlr1c1) returns: C215
Cheers, Dale
Place the column number which you need to know the character in the cell “B1”
And use the below formula rest of any cells
=LEFT(REPLACE(CELL(“address”,OFFSET(A1,1,B1-1)),1,1,”),FIND(“$”,REPLACE(CELL(“address”,OFFSET(A1,1,B1-1)),1,1,”))-1)
It’s Good
and help full