|
楼主 |
发表于 2019-12-21 06:10
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 YZC51 于 2019-12-21 22:14 编辑
'学习LDY 和 大理 两位版主的代码。谢谢老师们!
Function ToN(ss)
If Len(ss) = 0 Then ToN = "": Exit Function
xsd = InStr(ss & ".", "."): xs = Mid(ss, xsd + 1) '中文财务及大小写数字转阿拉伯数字
ss = Mid(ss, 1, xsd - 1) & "元"
dh = "毛圆十百千萬億": hc = "角元拾佰仟万亿"
For i% = 1 To 9
ss = Replace(ss, Mid("壹贰叁肆伍陆柒捌玖", i, 1), i) '取中文大写整数
ss = Replace(ss, Mid("一二三四五六七八九", i, 1), i) '取中文小写整数
ss = Replace(ss, Mid(dh, i, 1), hc) '替换不规范中文大小写
If Len(xs) = 0 Then GoTo xx
xs = Replace(xs, Mid("壹贰叁肆伍陆柒捌玖", i, 1), i) '取中文大写小数
xs = Replace(xs, Mid("一二三四五六七八九", i, 1), i) '取中文小写小数
xx:
Next
xs = "0." & xs '合成小数
For i% = Len(ss) To 1 Step -1 '生成占位 0
s$ = Mid$(ss, i, 1)
x% = InStr("分角元拾佰仟万拾佰仟亿拾佰仟兆", s)
If x Then j% = IIf(j% < x, x, ((j - 3) \ 4) * 4 + x)
If Val(s) Then m# = m# + (s & String(j - 1, "0")) / 100
Next
ToN = m + xs: If InStr(ss, "-") Or InStr(ss, "负") Then ToN = -ToN
End Function
|
评分
-
1
查看全部评分
-
|