Public Function NumtoCol(Numbers As Integer) As String
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim s1 As String, s2 As String, s3 As String
i2 = Numbers \ 26
i3 = i2 \ 26 '第3位
i2 = i2 Mod 26 '第2位
i1 = Numbers Mod 26 '第1位
If i2 > 0 And i1 = 0 Then
i1 = 26
i2 = i2 - 1
End If
If i3 > 0 And i2 = 0 Then
i2 = 26
i3 = i3 - 1
End If
s3 = Chr(i3 + 64)
s2 = Chr(i2 + 64)
s1 = Chr(i1 + 64)
If s3 = "@" Then
If s2 = "@" Then
NumtoCol = s1
Else
NumtoCol = s2 & s1
End If
Else
NumtoCol = s3 & s2 & s1
End If
End Function
Sub 显示列号()
With Worksheets("sheet1")
.Activate
.Range("AZ1").Select
End With
MsgBox Selection.Column
End Sub
Sub 测试显示列号()
Dim intCol As Integer
intCol = Val(InputBox("请输入列号(1~16384):"))
If intCol < 1 Or intCol > 16384 Then
MsgBox "输入的数据超过范围,请重新输入!"
Exit Sub
End If
MsgBox "列号:" & intCol & ",对应的字母为:" & NumtoCol(intCol)
End Sub