這篇文章為大家帶來了關於excel的相關知識,其中主要整理了將人民幣數字金額轉為中文大寫的方法,下面一起來看一下,希望對大家有幫助。
相關學習推薦:excel教學
#要將數字金額轉為中文大寫,需要經歷以下幾個步驟:
1.將阿拉伯小寫數字轉為中文大寫。這可以用到前面章節範例中,將數字轉換為中文大寫的程式碼,如:
Function RmbDx(ByVal c) As String<br>Application.Volatile True<br>c = Val (c)<br>RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")<br>RmbDx = Replace(RmbDx, "-", "負")<br>End Function
2.在整數金額的後面加上「元整」.可以藉助IF語句及FIX取整數函數來判斷某個金額是否整數金額。
Function RmbDx(ByVal c) As String<br><br>#Function RmbDx(ByVal c) As String<br>Application.Volatile True<br>c = Val(c)<br>RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2] ")<br>RmbDx = Replace(RmbDx, "-", "負")<br>If c = Fix(c) Then<br>RmbDx = RmbDx & "元整"
End If
3.在只包含「角」訊息,不含「分」訊息的金額中加上「元」和「分」訊息.<br><br>Function RmbDx (ByVal c) As String<br>Application.Volatile True<br>Dim p As Integer<br>c = Val(c)<br>RmbDx = Application.WorksheetFunction.Text(c, "[DBNum2]")<br>RmbDx = Replace(RmbDx, "-", "負")<br>If c = Fix(c) Then<br>RmbDx = RmbDx & "元整"<br>Else<br>RmbDx = Replace(RmbDx, ".", "元")<br>If c * 10 = Fix(c * 10) Then<br>RmbDx = RmbDx & "角"<br>End If
End If
4.在包含「角」與「分」資訊的資料中加入「角」和「分」資訊。 <br><br>Function RmbDx(ByVal c) As String<br><br>#Function RmbDx(ByVal c) As String<br>Application.Volatile True<br>Dim p As Integer<br>c = Val(c)<br>RmbDx = Application.WorksheetFunction.Text (c, "[DBNum2]")<br>RmbDx = Replace(RmbDx, "-", "負")<br>If c = Fix(c) Then<br>RmbDx = RmbDx & "元整"<br>Else<br>p = InStr(RmbDx, ".")<br>RmbDx = Replace(RmbDx, ".", "元")<br>If c * 10 = Fix(c * 10) Then<br> RmbDx = RmbDx & "角"<br>Else
RmbDx = Left(RmbDx, p) & Mid(RmbDx, p 1, 1) & "角" & Right(RmbDx, 1) & "分"
End If
End Function這樣即可得到將人民幣金額轉換為中文大寫金額的自訂函數RmbDx,效果如下圖。 ###相關學習推薦:###excel教學######以上是四步驟教你Excel將人民幣數字金額轉為中文大寫的詳細內容。更多資訊請關注PHP中文網其他相關文章!