如何在excel中设置公式将数字转换为英文大写金额?

如何在excel中设置公式将数字转换为英文大写金额?前些天有人问过转中文大写的,转英文金额有点复杂,我们一起尝试下,先看动态效果图:转英文金额相对于转中文金额难度要大,得自定义一个函数。

大家好,欢迎来到IT知识分享网。

前些天有人问过转中文大写的,转英文金额有点复杂,我们一起尝试下,先看动态效果图:

如何在excel中设置公式将数字转换为英文大写金额?

转英文金额相对于转中文金额难度要大,得自定义一个函数

1. 我们首先新建一个宏函数“数字转英文”,左下角右键“查看代码”,在弹出的窗口中插入一个新模板,将代码粘贴上去。

如何在excel中设置公式将数字转换为英文大写金额?

2. 之后在单元格内插入函数’fx’—-‘用户定义’—–‘数字转英文’—–‘确定’!

如何在excel中设置公式将数字转换为英文大写金额?

3. 最后在需要转换英文的单元格填充好公式就可以了!

具体代码如下:

Function 数字转英文(ByVal pNumber)

Dim Dollars, Cents

arr = Array(”, ”, ‘ Thousand ‘, ‘ Million ‘, ‘ Billion ‘, ‘ Trillion ‘)

pNumber = Trim(Str(pNumber))

xDecimal = InStr(pNumber, ‘.’)

If xDecimal > 0 Then

Cents = GetTens(Left(Mid(pNumber, xDecimal 1) & ’00’, 2))

pNumber = Trim(Left(pNumber, xDecimal – 1))

End If

xIndex = 1

Do While pNumber <> ”

xHundred = ”

xValue = Right(pNumber, 3)

If Val(xValue) <> 0 Then

xValue = Right(‘000’ & xValue, 3)

If Mid(xValue, 1, 1) <> ‘0’ Then

xHundred = GetDigit(Mid(xValue, 1, 1)) & ‘ Hundred ‘

End If

If Mid(xValue, 2, 1) <> ‘0’ Then

xHundred = xHundred & GetTens(Mid(xValue, 2))

Else

xHundred = xHundred & GetDigit(Mid(xValue, 3))

End If

End If

If xHundred <> ” Then

Dollars = xHundred & arr(xIndex) & Dollars

End If

If Len(pNumber) > 3 Then

pNumber = Left(pNumber, Len(pNumber) – 3)

Else

pNumber = ”

End If

xIndex = xIndex 1

Loop

Select Case Dollars

Case ”

Dollars = ‘No Dollars’

Case ‘One’

Dollars = ‘One Dollar’

Case Else

Dollars = Dollars

End Select

Select Case Cents

Case ”

Cents = ‘ and No Cents’

Case ‘One’

Cents = ‘ and One Cent’

Case Else

Cents = ‘ and ‘ & ‘Cents ‘ & Cents

End Select

数字转英文 = ‘US Dollar ‘ & Dollars & Cents

End Function

Function GetTens(pTens)

Dim Result As String

Result = ”

If Val(Left(pTens, 1)) = 1 Then

Select Case Val(pTens)

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(pTens, 1))

Case 2: Result = ‘Twenty ‘

Case 3: Result = ‘Thirty ‘

Case 4: Result = ‘Forty ‘

Case 5: Result = ‘Fifty ‘

Case 6: Result = ‘Sixty ‘

Case 7: Result = ‘Seventy ‘

Case 8: Result = ‘Eighty ‘

Case 9: Result = ‘Ninety ‘

Case Else

End Select

Result = Result & GetDigit(Right(pTens, 1))

End If

GetTens = Result

End Function

Function GetDigit(pDigit)

Select Case Val(pDigit)

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

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/59387.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信