EXCEL电子表格:将数字转换成英文金额

在工作中可能用到在EXCEL中输入一个数字,可以自动转换成英文金额标识。EXCEL或WPS通过VBA自定义函数可以实现。

1. 新建Excel表格

2. 按住"AIt+F11”打开VBA编辑器

3. 在VBA编辑器中单击菜单栏"插入→模块

4. 在打开的模块中输入如下代码→保存→回到excel界面:

 Function 数字转英文大写金额(ByVal MyNumber)
    Dim Dollars, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Application.Volatile True
    Place(2) = " THOUSAND "
    Place(3) = " MILLION "
    Place(4) = " BILLION "
    Place(5) = " TRILLION "
    MyNumber = Trim(Str(MyNumber))
    DecimalPlace = InStr(MyNumber, ".")
    If DecimalPlace > 0 Then
        Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
        End If
    Count = 1
    Do While MyNumber <> ""
       Temp = GetHundreds(Right(MyNumber, 3))
       If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
          If Len(MyNumber) > 3 Then
             MyNumber = Left(MyNumber, Len(MyNumber) - 3)
             Else
            MyNumber = ""
            End If
            Count = Count + 1
            Loop
    Select Case Dollars
        Case ""
            Dollars = ""
        Case "One"
            Dollars = "One Dollar"
        Case Else
            Dollars = "ASY US DOLLARS " & Dollars & " ONLY"  '/* 注释:&前、后可增加内容 */'
    End Select
    数字转英文大写金额 = Dollars
    End Function
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " HUNDRED "
        End If
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
        Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
        End If
    GetHundreds = Result
    End Function
Function GetTens(TensText)
    Dim Result As String
    Result = ""
    If Val(Left(TensText, 1)) = 1 Then
        Select Case Val(TensText)
        Case 10: Result = "Ten"
            Case 11: Result = "ELEVEN"
            Case 12: Result = "TWELVE"
            Case 13: Result = "THIRTEEN"
            Case 14: Result = "FOURTEEN"
            Case 15: Result = "FIFTEEN"
            Case 16: Result = "SIXTEEN"
            Case 17: Result = "SEVENTEEN"
            Case 18: Result = "EIGHTEEN"
            Case 19: Result = "NINETEEN"
            Case Else
            End Select
      Else
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "AND TWENTY "
            Case 3: Result = "AND THIRTY "
            Case 4: Result = "AND FORTY "
            Case 5: Result = "AND FIFTY "
            Case 6: Result = "AND SIXTY "
            Case 7: Result = "AND SEVENTY "
            Case 8: Result = "AND EIGHTY "
            Case 9: Result = "AND NINETY "
            Case Else
        End Select
         Result = Result & GetDigit _
            (Right(TensText, 1))
            End If
      GetTens = Result
      End Function
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "ONE"
        Case 2: GetDigit = "TWO"
        Case 3: GetDigit = "THREE"
        Case 4: GetDigit = "FOUR"
        Case 5: GetDigit = "FIVE"
        Case 6: GetDigit = "SIX"
        Case 7: GetDigit = "SEVEN"
        Case 8: GetDigit = "EIGHT"
        Case 9: GetDigit = "NINE"
        Case Else: GetDigit = ""
    End Select
End Function

*代码来自网络

5. EXCEL插入函数,或选择类别-用户自定义-“数字转英文大写金额”这个函数,引用即可。

例:如在A1录入阿拉伯数字,在B1中插入函数“=数字转英文大写金额(A1)”。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值