Home

Consulting

Excel VBA

Legal

Links

Contact

About Us

Convert A Column Number To A Letter

Many times in Excel you have a column number and need to convert it to a collumn letter. Excel lacks a Column Letter property. The below routine will return this for you.
 
'********************************************************************
'  http://www.KravatzInc.com    1-866-XLS-PROG
'
'  This code is copyrighted by Kravatz, Inc. (c) 2007 All Rights Reserved.
'  You may use this code as long as this message appears
'  There is no warranty made to the fitness or suitablilty of this code
'  and by using it you hold Kravatz, Inc. harmless for any damages
'  that may result from its use.  This code is supplied as is.
'  
'********************************************************************

Function ColumnLetter(ColumnNumber As Long) As String
  If ColumnNumber > 26 Then
      ' 2 digit column
       ColumnLetter = Chr(Int((ColumnNumber - 1) / 26) + 64)  'First Character
       ColumnLetter = ColumnLetter & _
                        Chr(((ColumnNumber - 1) Mod 26) + 65) 'Second Character 
  Else
    
    ColumnLetter = Chr(ColumnNumber + 64)
  End If
End Function