user4039065 很接近,但是行尾的下标应该是(2)。然后,例如,677 代表列“ZA”,列 16384 代表“XFD”,通过以下函数:
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
事实上,如果我使用(1) 代替我的(2),那么对于第26 列,我会得到Z:,而不仅仅是Z,如下所述。
Split 函数与有效的 Excel 列地址一起使用时,返回一个长度为 3 的数组,分阶段显示最终结果是如何得出的。
以256为例,msg代码块显示的结果为:
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 "返回一个从零开始的一维数组,包含 ... '所有子字符串' "(如果省略了limit(第三个)参数)给定表达式(第一个参数)。