http://www.pptjcw.com

excel宏教程:将人民币数字金额转为中文大写

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

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

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

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

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

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

    Function RmbDx(ByVal c) As String
    Application.Volatile True
    Dim p As Integer
    c = Val(c)
    RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")
    RmbDx = Replace(RmbDx, "-", "负")
    If c = Fix(c) Then
    RmbDx = RmbDx & "元整"
    Else
    RmbDx = Replace(RmbDx, ".", "元")
    If c * 10 = Fix(c * 10) Then
    RmbDx = RmbDx & "角"
    End If
    End If
    End Function

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

    Function RmbDx(ByVal c) As String
    Application.Volatile True
    Dim p As Integer
    c = Val(c)
    RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")
    RmbDx = Replace(RmbDx, "-", "负")
    If c = Fix(c) Then
    RmbDx = RmbDx & "元整"
    Else
    p = InStr(RmbDx, ".")
    RmbDx = Replace(RmbDx, ".", "元")
    If c * 10 = Fix(c * 10) Then
    RmbDx = RmbDx & "角"
    Else
    RmbDx = Left(RmbDx, p) & Mid(RmbDx, p + 1, 1) & "角" & Right(RmbDx, 1) & "分"
    End If
    End If
    End Function

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

    excel宏教程:将人民币数字金额转为中文大写

    提示:如果您觉得本文不错,请点击分享给您的好友!谢谢

    上一篇:excel教程:批量新建指定名称的工作表 下一篇:excel入门教程:用VBA将单元格的格式复制粘贴到另一个区域中

    郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。