
用 VBA 自定义函数解决(调用:B1 = Dec2Base36(A1))
Function Dec2Base36(rg As Integer) As String
jz = 36
rt = ""
If rg < jz Then
rt = num2str(rg)
Else
笑基 tg = rg
While tg >= jz
碰液谨 zc = Int(tg / jz)
ys = tg - zc * jz
rt = num2str(ys) & rt
tg = zc
Wend
埋盯 rt = num2str(tg) & rt
End If
Dec2Base36 = rt
End Function
Function num2str(n) As String
If n > 9 Then
n = n + 55
rt = Chr(n)
Else
rt = n
End If
num2str = rt
End Function
1、用VBA写一个自定义函数,如函数名写为 to36( )
按局毁键ALT+F11,则打开VBA代码编辑器,
菜单中[插入]敏仔―[模块],粘贴桥腊汪以下代码进去。
Function to36(a As Long)
n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Do
If a < 36 Then n = Mid(n, a + 1, 1) & n: Exit Do
m = a Mod 36
n = Mid(n, m + 1, 1) & n
If a = 36 Then n = 1 & n: Exit Do
a = (a - m) / 36
Loop
End Function
2,在单元格中设置公式,并使用以上的自定义函数,
如在 A1中输入100, B1中设置公式 =to36(A1) , 结果显示为36进制的 2S
不知道问题是不是有误?还有36进制一说吗,只知道16进制的。
转换可以使用函数:DEC2HEX
DEC2HEX(number, [places])
DEC2HEX 函数语法具有下列参数 (参数:前世为操作、事件、方法、属性、函数或过程提供信祥配息慧宴肢的值。):
Number 必需。待转换的十进制整数。如果参数 number 是负数,则省略 places,并且函数
DEC2HEX 返回 10 个字符的十六进制数(40 位二进制数),其最高位为符号位,其余 39 位是数字位。负数用二进制数的补码表示。
Places 可选。要使用的字符数。如果省略 places,函数 DEC2HEX
用能表示此数的最少字符来表示。当需要在返回的值前置 0(零)时,places 尤其有用。
参考百科:http://baike.baidu.com/link?url=9RKnBvXi3mCOkPuvLmlj1CJLIOBRrOSqwUILcsKAi8tXMuNd1a4Jel6gFjpFMngAM52Yyf3htEHXbgeZJ-n_7_
vba...
俺毕世颂写出来了:
VBA自定义函数:
Function s(a As Long)
v = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Do
If a < 36 Then s = Mid(v, a + 1, 1) & s: Exit Do
m = a Mod 36
s = Mid(v, m + 1, 1) & s
If a = 36 Then s = 1 & s: Exit Do
a = (a - m) / 36
Loop
End Function
懂VBA的以下不用看:
使用方法:
1,按键ALT+F11
2,菜单选插入――模块,将以上代手郑码粘贴进去。
如果EXCEL宏安全级别设为的的话,现在就可以使用这个返源函数了。
例如在啊A1中输入=s(100),将显示2S