user4039065 is very close, but the subscript at the end of the line should be (2)
. Then, e.g., 677 represents column "ZA" and column 16384 represents "XFD" by the function below:
Const MAX_COL_NUMBER = 16384
...
Function columnNumberToColumnString(col As Integer) As String
If col > MAX_COL_NUMBER Or col < 1 Then
columnNumberToColumnString = "ERROR": Exit Function
Else
columnNumberToColumnString = Split(Columns(col).Address, "$")(2)
End If
' delete code block below after seeing how Split works
msg = "Split <" & Columns(col).Address & ">"
For i = 0 To UBound(Split(Columns(col).Address, "$"))
msg = msg + Chr(13) & Chr(10) & "Substring " & i & _
" is <" & Split(Columns(col).Address, "$")(i) & ">"
Next
MsgBox msg
End Function
In fact, if I use (1)
in place of my (2)
, for column 26 I get Z:
, not just Z
, as explained below.
The Split
function, when used with a valid Excel column address, returns an array of length 3, showing in stages how the final result is arrived at.
For 256, for example, the results displayed by the msg
code block are:
Address of column number 256 is <$IV:$IV>
Substring 0 is <> (since first $ is first character, strip it and all after)
Substring 1 is <IV:> (since second $ is after the :, strip it and all after)
Substring 2 is <IV> (since : above is a usual delimiter, strip it)
Split
"Returns a zero-based, one-dimensional array containing ... 'all substrings' " (if the limit
(third) argument is omitted) of the given expression (first argument).