This works fine in MS Excel 2003-2010. Should work for previous versions supporting the Cells(...).Address function:
- For the 28th column - taking
columnNumber=28
; Cells(1, columnNumber).Address
returns "$AB$1"
.
- Doing a split on the
$
sign returns the array: ["","AB","1"]
- So
Split(Cells(1, columnNumber).Address, "$")(1)
gives you the column name "AB"
.
UPDATE:
Taken from How to convert Excel column numbers into alphabetical characters
' The following VBA function is just one way to convert column number
' values into their equivalent alphabetical characters:
Function ConvertToLetter(iCol As Integer) As String
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int(iCol / 27)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
End Function
APPLIES TO: Microsoft Office Excel 2007 SE / 2002 SE / 2000 SE / 97 SE