|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Attribute VB_Name = "人民币大写"
- Sub 人民币大写()
- '
- ' 人民币大写 宏
- '
- '
- Dim tb
- Dim s, s1, s2, s3
- Dim i, k, l, n
-
-
- s = "壹贰叁肆伍陆柒捌玖零"
- s1 = "亿仟佰拾万仟佰拾元角分"
-
- Set tb = Documents(1).Tables(1)
-
- s2 = Replace(tb.Cell(1, 1), Chr(13) & Chr(7), "")
-
- s2 = s2 * 100
-
- l = Len(s2)
- k = Len(s1)
-
- For i = 1 To l
- n = Mid(s2, i, 1)
- If n = 0 Then n = 10
- 'k = l
- s3 = s3 & Mid(s, n, 1) & Mid(s1, 11 - l + i, 1)
- 'k = k - 1
- Next
-
- s3 = Replace(s3, "零万", "万")
- s3 = Replace(s3, "零仟", "零")
- s3 = Replace(s3, "零佰", "零")
- s3 = Replace(s3, "零拾", "零")
- s3 = Replace(s3, "零元", "元")
- s3 = Replace(s3, "零角", "零")
- s3 = Replace(s3, "零分", "")
-
- s3 = Replace(s3, "零零零万", "零")
- s3 = Replace(s3, "零零万", "万")
- s3 = Replace(s3, "零万", "万")
- s3 = Replace(s3, "零零零零零", "零")
- s3 = Replace(s3, "零零零零", "零")
- s3 = Replace(s3, "零零零", "零")
- s3 = Replace(s3, "零零", "零")
- s3 = Replace(s3, "零元", "元")
-
- If Right(s3, 2) = "元零" Then
- s3 = Replace(s3, "元零", "元整")
- End If
- tb.Cell(1, 3) = "人民币大写:" & s3
-
- Set tb = Nothing
-
- End Sub
复制代码 自己试了下,能转换亿以内的数据,没添加数据检测,没有数据查找。
|
|