2016 - 2024

感恩一路有你

excel怎么让数字变大写人民币金额 Excel如何将数字转为人民币金额大写

浏览量:2132 时间:2023-11-30 11:35:05 作者:采采

在Excel中,我们经常需要将数字转换为人民币金额大写,例如将1000转换为壹仟元整。下面我们将详细介绍几种方法实现这个功能。

方法一:使用Excel内置函数

Excel提供了一个内置函数“人民币大写”,可以直接将数字转换为人民币金额大写。具体操作如下:

1. 在目标单元格中输入要转换的数字。

2. 选择目标单元格,点击“公式”选项卡,在函数库中选择“文本”类别下的“人民币大写”函数。

3. 在函数参数对话框中,选择“小写金额”并设置为目标单元格的引用。

4. 点击“确定”按钮,将数字转换为人民币金额大写。

方法二:使用自定义宏

除了使用内置函数,我们也可以通过编写宏来实现数字转换为人民币金额大写。具体操作如下:

1. 按下“Alt F11”快捷键,打开“Visual Basic for Applications”编辑器。

2. 在编辑器中,选择“插入”菜单中的“模块”,创建一个新的模块。

3. 在模块中编写以下VBA代码:

```

Function ConvertToRMB(ByVal MyNumber)

Dim Units As String

Dim TempStr As String

Dim DecimalPlace As Integer

Dim Count As Integer

ReDim Place(9) As String

Place(2) " Thousand "

Place(3) " Million "

Place(4) " Billion "

Place(5) " Trillion "

Count 1

ReDim DecimalPlace(2) As String

DecimalPlace(0) " Dollars "

DecimalPlace(1) " Cents "

DecimalPlace(2) " Only "

ReDim Temp(6) As String

Temp(1) " One "

Temp(2) " Two "

Temp(3) " Three "

Temp(4) " Four "

Temp(5) " Five "

Temp(6) " Six "

Temp(7) " Seven "

Temp(8) " Eight "

Temp(9) " Nine "

ReDim Dollars(4) As String

Dollars(1) " Ten "

Dollars(2) " Twenty "

Dollars(3) " Thirty "

Dollars(4) " Forty "

Dollars(5) " Fifty "

Dollars(6) " Sixty "

Dollars(7) " Seventy "

Dollars(8) " Eighty "

Dollars(9) " Ninety "

ReDim Ones(9) As String

Ones(1) " One "

Ones(2) " Two "

Ones(3) " Three "

Ones(4) " Four "

Ones(5) " Five "

Ones(6) " Six "

Ones(7) " Seven "

Ones(8) " Eight "

Ones(9) " Nine "

ReDim Teens(9) As String

Teens(1) " Eleven "

Teens(2) " Twelve "

Teens(3) " Thirteen "

Teens(4) " Fourteen "

Teens(5) " Fifteen "

Teens(6) " Sixteen "

Teens(7) " Seventeen "

Teens(8) " Eighteen "

Teens(9) " Nineteen "

MyNumber Trim(Str(MyNumber))

DecimalPlace InStr(MyNumber, ".")

If DecimalPlace > 0 Then

TempStr GetTens(Left(Mid(MyNumber, DecimalPlace 1) "00", 2))

MyNumber Trim(Left(MyNumber, DecimalPlace - 1))

End If

Count 1

Do While MyNumber <> ""

ReDim Preserve Tens(Count) As String

ReDim Preserve Result(Count) As String

If Len(MyNumber) > 3 Then

TempNumber GetHundreds(Right(MyNumber, 3))

MyNumber Left(MyNumber, Len(MyNumber) - 3)

Else

TempNumber GetHundreds(MyNumber)

MyNumber ""

End If

If TempNumber <> "" Then Result(Count) TempNumber Place(Count) Result(Count)

If Len(MyNumber) 1 Then Result(Count) Result(Count) GetDigit(MyNumber) : MyNumber ""

If Len(MyNumber) 2 Then Result(Count) Result(Count) GetTens(MyNumber) : MyNumber ""

If Len(MyNumber) 3 Then Result(Count) Result(Count) GetHundreds(MyNumber) : MyNumber ""

Count Count 1

Loop

ConvertToRMB Trim(Join(Result, ""))

End Function

Private Function GetDigit(ByVal 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

Private Function GetTens(TensText)

Dim Result As String

Result "" ' Null out the temporary function value.

If Val(Left(TensText, 1)) 1 Then ' If value between 10-19...

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 ' If value between 20-99...

Select Case Val(Left(TensText, 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(TensText, 1)) ' Retrieve ones place.

End If

GetTens Result

End Function

Private Function GetHundreds(ByVal MyNumber)

Dim Result As String

If Val(MyNumber) 0 Then Exit Function

MyNumber Right("000" MyNumber, 3)

' Convert the hundreds place.

If Mid(MyNumber, 1, 1) <> "0" Then

Result GetDigit(Mid(MyNumber, 1, 1)) " Hundred "

End If

' Convert the tens and ones place.

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

```

4. 关闭编辑器,返回Excel界面。

5. 在目标单元格中输入要转换的数字。

6. 在目标单元格中输入以下公式:`ConvertToRMB(A1)`(假设要转换的数字位于A1单元格),按下回车键即可将数字转换为人民币金额大写。

通过以上两种方法,你可以将任意数字转换为人民币金额大写并在Excel中使用。希望本文能够帮助到你!

Excel 数字转换 人民币金额大写

版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。