将人民币数字金额转为中文大写

网友投稿 591 2022-10-07

将人民币数字金额转为中文大写

本文为《别怕,Excel VBA其实很简单(第3版)》随书问题参-

要将数字金额转为中文大写,需要经历以下几个步骤:

1.将阿拉伯小写数字转为中文大写。这可以用到前面章节例子中,将数字转为中文大写的代码,如:

Function RmbDx(ByVal c) As StringApplication.Volatile Truec = Val(c)RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")RmbDx = Replace(RmbDx, "-", "负")End Function

2.在整数金额的后面添加“元整”.可以借助IF语句及FIX取整函数来判断某个金额是否整数金额。

将人民币数字金额转为中文大写

Function RmbDx(ByVal c) As StringApplication.Volatile Truec = Val(c)RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")RmbDx = Replace(RmbDx, "-", "负")If c = Fix(c) ThenRmbDx = RmbDx & "元整"End IfEnd Function

3.在只包含“角”信息,不含“分”信息的金额中添加“元”和“分”信息.

Function RmbDx(ByVal c) As StringApplication.Volatile TrueDim p As Integerc = Val(c)RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")RmbDx = Replace(RmbDx, "-", "负")If c = Fix(c) ThenRmbDx = RmbDx & "元整"ElseRmbDx = Replace(RmbDx, ".", "元")If c * 10 = Fix(c * 10) ThenRmbDx = RmbDx & "角"End IfEnd IfEnd Function

4.在包含“角”与“分”信息的数据中添加“角”和“分”信息。

Function RmbDx(ByVal c) As StringApplication.Volatile TrueDim p As Integerc = Val(c)RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")RmbDx = Replace(RmbDx, "-", "负")If c = Fix(c) ThenRmbDx = RmbDx & "元整"Elsep = InStr(RmbDx, ".")RmbDx = Replace(RmbDx, ".", "元")If c * 10 = Fix(c * 10) ThenRmbDx = RmbDx & "角"ElseRmbDx = Left(RmbDx, p) & Mid(RmbDx, p + 1, 1) & "角" & Right(RmbDx, 1) & "分"End IfEnd IfEnd Function

这样即可得到将人民币金额转为中文大写金额的自定义函数RmbDx,效果如下图。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:几个常用函数的功能与应用范例
下一篇:用VBA按列信息拆分数据到多工作簿
相关文章