将Excel中列数转为列号
2009-10-17 21:56 Format Deng 阅读(527) 评论(0) 编辑 收藏 举报一段将Excel中列数转为列号的VBA代码
1Function NumToChar_26(Num As Double) As String
2 '--===Writen By FormatD
3 '将Excel中列数转为列号
4 Dim iMod As Integer, dInt As Double, sChar As String
5 'Application.Volatile
6 iMod = Num Mod 26
7 dInt = Num \ 26
8 If iMod > 0 Then
9 sChar = Split(Columns(iMod).Address(0, 0), ":")(0)
10 ElseIf dInt > 0 Then
11 dInt = dInt - 1
12 sChar = "Z"
13 End If
14 Do While dInt > 0
15 iMod = dInt Mod 26
16 dInt = dInt \ 26
17 If iMod > 0 Then
18 sChar = Split(Columns(iMod).Address(0, 0), ":")(0) & sChar
19 ElseIf dInt > 0 Then
20 dInt = dInt - 1
21 sChar = "Z" & sChar
22 End If
23 Loop
24 NumToChar_26 = sChar
25End Function
2 '--===Writen By FormatD
3 '将Excel中列数转为列号
4 Dim iMod As Integer, dInt As Double, sChar As String
5 'Application.Volatile
6 iMod = Num Mod 26
7 dInt = Num \ 26
8 If iMod > 0 Then
9 sChar = Split(Columns(iMod).Address(0, 0), ":")(0)
10 ElseIf dInt > 0 Then
11 dInt = dInt - 1
12 sChar = "Z"
13 End If
14 Do While dInt > 0
15 iMod = dInt Mod 26
16 dInt = dInt \ 26
17 If iMod > 0 Then
18 sChar = Split(Columns(iMod).Address(0, 0), ":")(0) & sChar
19 ElseIf dInt > 0 Then
20 dInt = dInt - 1
21 sChar = "Z" & sChar
22 End If
23 Loop
24 NumToChar_26 = sChar
25End Function