您的位置:首页 > 编程语言 > VB

vba将列名的字母转为数字

2016-03-06 12:54 429 查看
'transfer column from "A" to 1, from "Z" to 26 ......
Private Function ColumnNum(ByVal a) As Long
Dim r
r = 0
If VarType(a) = vbString And Len(a) > 0 Then
a = UCase(a)
r = Asc(Left(a, 1)) - Asc("A") + 1
If Len(a) >= 2 Then
r = r * 26 + Asc(Mid(a, 2, 1)) - Asc("A") + 1
If Len(a) >= 3 Then
r = r * 26 + Asc(Mid(a, 3, 1)) - Asc("A") + 1
End If
End If
End If
ColumnNum = r
End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: