標題:
[分享]
數字轉國字金額(可變成公式使用)
[打印本頁]
作者:
PKKO
時間:
2015-4-21 15:13
標題:
數字轉國字金額(可變成公式使用)
本帖最後由 PKKO 於 2015-4-21 15:21 編輯
各位大大好,此為小弟在網路上搜尋之後進行小改版,方便各位直接使用
重要說明:因為小弟的金額只用到佰萬元以內,因此此程式只適用於佰萬元以內,若要增加可自行修改
方式如下
一、插入模組
二、將此程式碼完整貼上
三、在公式的位置直接打上=Money(A1)
就會直接出現國字金額了
若需要"元整",就直接修改VBA或是修改=Money(A1) &"元整"
若有錯誤還請各位提出,個人測試後使用無誤
Function Money(Mny As String) As String
Dim w(10), z(10), r(10)
word = Mny
For i = 1 To Len(word)
w(i) = Mid(word, i, 1)
If w(i) = 0 Then r(i) = "零"
If w(i) = 1 Then r(i) = "壹"
If w(i) = 2 Then r(i) = "貳"
If w(i) = 3 Then r(i) = "參"
If w(i) = 4 Then r(i) = "肆"
If w(i) = 5 Then r(i) = "伍"
If w(i) = 6 Then r(i) = "陸"
If w(i) = 7 Then r(i) = "柒"
If w(i) = 8 Then r(i) = "捌"
If w(i) = 9 Then r(i) = "玖"
Next i
If r(6) <> "零" Then
z(7) = ("佰")
Else
z(7) = ("佰萬")
End If
If r(5) <> "零" Then
z(6) = ("拾")
Else
z(6) = ("拾萬")
End If
z(5) = ("萬")
z(4) = ("仟")
z(3) = ("佰")
z(2) = ("拾")
z(1) = ""
i = 1
L = Len(word)
aa = ""
Do While L > 0
If r(i) <> "零" Then
aa = aa & r(i) & z(L)
End If
i = i + 1
L = L - 1
Loop
Money = aa
End Function
複製代碼
作者:
PKKO
時間:
2015-4-21 15:37
回復
1#
PKKO
抱歉,上方程式有誤,已修正如下,並修正為可使用至千萬元
Function Money(Mny As String) As String
Dim w(10), z(10), r(10)
word = Mny
For i = 1 To Len(word)
w(i) = Mid(word, i, 1)
If w(i) = 0 Then r(i) = "零"
If w(i) = 1 Then r(i) = "壹"
If w(i) = 2 Then r(i) = "貳"
If w(i) = 3 Then r(i) = "參"
If w(i) = 4 Then r(i) = "肆"
If w(i) = 5 Then r(i) = "伍"
If w(i) = 6 Then r(i) = "陸"
If w(i) = 7 Then r(i) = "柒"
If w(i) = 8 Then r(i) = "捌"
If w(i) = 9 Then r(i) = "玖"
Next i
If Left(Right(word, 7), 1) Then
z(8) = ("仟")
Else
z(8) = ("仟萬")
End If
If Left(Right(word, 6), 1) <> 0 Then
z(7) = ("佰")
Else
z(7) = ("佰萬")
End If
If Left(Right(word, 5), 1) <> 0 Then
z(6) = ("拾")
Else
z(6) = ("拾萬")
End If
z(5) = ("萬")
z(4) = ("仟")
z(3) = ("佰")
z(2) = ("拾")
z(1) = ""
i = 1
L = Len(word)
aa = ""
Do While L > 0
If r(i) <> "零" Then
aa = aa & r(i) & z(L)
End If
i = i + 1
L = L - 1
Loop
Money = aa
End Function
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)