Skip to: Site menu | Main content

Login

Name: 
Password:
Remember me?
Register

Obtaining Column Letter From its Number

written by Mark Rowlinson - Last updated Nov 2004

There are many ways to determine the column letter relating to a given number in Excel. Among the worst of these I've seen is a typed array of letters! This is one of the better ways:

 
Function GetColumnAlpha(x As Integer) As String 
    Dim y As String 
    y = Application.Cells(1, x).Address(FALSE, FALSE) 
    GetColumnAlpha = Left$(y, Len(y) - 1) 
End Function 
 

Currently the code will rasie a runtime error if you pass it a number greater than 255 or less than 1 i.e. out of the excel column boundaries. You could add a check in here if you wanted it to return a null string for example instead e.g.
 
Function GetColumnAlpha(x As Integer) As String 
    Dim y As String 
    If x>0 And x<256 Then 
        y = Application.Cells(1, x).Address(FALSE, FALSE) 
        GetColumnAlpha = Left$(y, Len(y) - 1) 
    End If 
End Function