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

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 Name1

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 Name2

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 Name3

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.

Column Number to Column Name

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.

Column Name to Number Conversion

Hey! Join Our Community

Get Quick Responses & Experts' Answers in Minutes!
Get Notified - When Answered Your Question!