楼主 BIN_YANG168 |
Q:怎样用自定义函数将大写中文金额转换为阿拉伯数字金额,如:壹仟贰佰叁拾肆元伍角柒分 变为:1234.57 A:按Alt+F11,插入→模块→在VBE窗口中输入以下代码:
- Function SuZi(A As String) ' 人民币中文大写转数字函数
- Application.Volatile True
- Hsf = "分角元拾佰仟万 亿"
- Hs = "零壹贰叁肆伍陆柒捌玖 "
- JH = 1
- A = Replace(A, "整", "")
- A = Replace(A, "亿", ")亿")
- A = Replace(A, "万", ")万")
- If A <> "" Then
- Mylen = Len(A$)
- For m = 1 To Mylen
- If Mid(A, m, 1) = "万" And JH = 1 Then A = "(" & A: JH = 0
- If Mid(A, m, 1) = "亿" Then
- A = "(" & A
- JH = 0
- For K = m + 3 To Mylen + 2
- If Mid(A$, K, 1) = "万" Then
- A = Replace(A, "亿", "亿(")
- Exit For
- End If
- Next
- Exit For
- End If
- Next
- For i = 0 To 10
- A = Replace(A, Mid(Hs, i + 1, 1), i)
- A = Replace(A, Mid(Hsf, i + 1, 1), "*" & (10 ^ (i - 2)) & "+")
- Next
- A = Replace(A, "+)", ")")
- A = Replace(A, "+*", "*")
- Mylen = Len(A)
- A = Left(A, Mylen - 1)
- SuZi = Evaluate(A)
- End If
- End Function
然后在A1单元格输入需要的大写中文金额,在其他单元格输入=SUZI (A1)即可。
大写中文金额转为阿拉伯数字.rar |