This is good if you like to use statements like Range("A1") instead of cells(1,1).
So, for example ColLetter(1) = A, ColLetter(2) = b, ... , ColLetter(100) = CV, etc.
3) ColLetter(column number) => passes back column Letter.
Public Function ColLetter(colNumber As Long) As String
If colNumber < 27 Then
If colNumber = 0 Then
ColLetter = "Z"
Else
ColLetter = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", colNumber, 1)
End If
Else
If colNumber < 26 ^ 2 + 27 Then
ColLetter = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", FLOOR(colNumber / 26), 1)
ColLetter = ColLetter & ColLetter(colNumber Mod 26)
Else
ColLetter = Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", FLOOR((colNumber - 26) / 676), 1)
ColLetter = ColLetter & ColLetter(colNumber - FLOOR((colNumber - 26) / 676) * 676)
End If
End If
End Function
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.
dim x as string
x=cells(1,colNumber).address(true,false)
ColLetter=left(x,instr(x,"$")-1)