|
本帖最后由 山中老人 于 2015-7-17 12:32 编辑
将 Column【数字列号】转换成【字母列名】
如:
1 =A
2 =B
3 =C
26 =Z
27 =AA
Sub 测试009()
Dim i As Long
i = 26
Debug.Print i & "=" & Excel_Column_Name(i)
i = 27
Debug.Print i & "=" & Excel_Column_Name(i)
For i = 1 To 256
Debug.Print i & "=" & Excel_Column_Name(i)
Next i
End Sub
Public Function Excel_Column_Name(Column) As String '单元格地址,从[C1R2] 转换为 "A2"
On Error GoTo err1
If Not IsNumeric(Column) Then GoTo err1
If Column < 1 Then GoTo err1
Dim a As Long, b As Long, Ctxt As String, C As Long
C = Int(Column)
Ctxt = ""
Do
C = C - 1
b = C Mod 26
C = Int(C / 26)
Ctxt = Chr(b + 65) & Ctxt
Loop While C > 0
Excel_Column_Name = Ctxt
Exit Function
err1:
Debug.Print "错误的列号:" & Column
End Function
|
|