Excel怎样数字转财务大写

如题所述

在Excel中将数字转换为财务大写可以通过使用内置的函数或自定义的VBA代码来实现。


首先,Excel内置了一些函数可以用来将数字转换为大写汉字。比如,可以使用TEXT函数和自定义的数字格式来实现。具体步骤如下:


1. 在需要转换数字的单元格旁边添加一个辅助列;


2. 在辅助列中使用以下公式:=TEXT(A1,"[DBNum2]")(假设A1是需要转换的数字单元格);


3. 然后将公式结果复制为值,即可得到财务大写的数字。


但是,这种方法只能将数字转换为简单的大写汉字,对于财务票据中需要的复杂格式,比如“壹、贰、叁、肆、伍、陆、柒、捌、玖、拾、佰、仟、万、亿”等,无法完全满足需求。


此时,可以通过自定义VBA代码来实现更加复杂的财务大写转换。具体步骤如下:


1. 打开Visual Basic for Applications(VBA)编辑器;


2. 插入一个新的模块,将以下代码复制粘贴进去:


Function NumToChinese(ByVal Num As Double) As String


Dim MyNumber As String


Dim DecimalPlace As String


Dim Count As Integer


Dim DecimalSeparator As String


Dim Unit As String


Dim SubUnit As String


Dim SubUnitName As String


Dim SubScale As String


Dim SubScaleName As String


Dim Quote As String


Dim Temp As String


Dim DecimalValue As String


Dim i As Integer


ReDim Place(9) As String


Place(2) = " Thousand "


Place(3) = " Million "


Place(4) = " Billion "


Place(5) = " Trillion "


MyNumber = Trim(Str(Num))


If MyNumber = "" Then


NumToChinese = ""


Exit Function


End If


DecimalPlace = InStr(MyNumber, ".")


DecimalSeparator = ""


If DecimalPlace > 0 Then


DecimalSeparator = " Point "


DecimalValue = 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 DecimalSeparator = " Thousand " & DecimalSeparator


If Len(MyNumber) > 3 Then


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


Else


MyNumber = ""


End If


NumToChinese = Temp & Place(Count) & NumToChinese


Count = Count + 1


Loop


Select Case DecimalValue


Case ""


NumToChinese = NumToChinese & " Dollars"


Case "00", ".00"


NumToChinese = NumToChinese & " Dollars and Cents"


Case Else


NumToChinese = NumToChinese & " Dollars and " & DecimalValue & " Cents"


End Select


End Function


Function GetHundreds(ByVal MyNumber As String) As String


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 "


If Mid(MyNumber, 2, 1) <> "0" Then Result = Result & GetTens(Mid(MyNumber, 2))


If Mid(MyNumber, 3, 1) <> "0" Then Result = Result & GetDigit(Mid(MyNumber, 3))


GetHundreds = Result


End Function


Function GetTens(TensText As String) As String


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 = "

温馨提示:答案为网友推荐,仅供参考
相似回答