922337203685477# Then SoRaChu =..." />
Nội dung hàm đọc số ra chữ trong Excel.
Function SoRaChu(ByVal NumCurrency As Currency) As String
If NumCurrency = 0 Then
SoRaChu = "Kh" & ChrW$(244) & "ng "
Exit Function
End If
If NumCurrency > 922337203685477# Then
SoRaChu = "Không d?i du?c s? l?n hon 922,337,203,685,477"
Exit Function
End If
'-------------------------------------------------
Static CharVND(9) As String, BangChu As String, I As Integer
Dim SoLe, SoDoi As Integer, PhanChan, Ten As String
CharVND(1) = "m" & ChrW$(7897) & "t"
CharVND(2) = "hai"
CharVND(3) = "ba"
CharVND(4) = "b" & ChrW$(7889) & "n"
CharVND(5) = "n" & ChrW$(259) & "m"
CharVND(6) = "s" & ChrW$(225) & "u"
CharVND(7) = "b" & ChrW$(7843) & "y"
CharVND(8) = "t" & ChrW$(225) & "m"
CharVND(9) = "ch" & ChrW$(237) & "n"
'-------------------------------------------------
SoLe = Int((NumCurrency - Int(NumCurrency)) * 100) '2 kí s? l?
I = 1
PhanChan = Trim$(Str$(Int(NumCurrency)))
While Len(PhanChan) > 0
Select Case I
Case 1 'Dong
Dong = Val(Right$(PhanChan, 3))
PhanChan = Left$(PhanChan, Len(PhanChan) - Len(Trim$(Str$(Dong))))
Case 2 'Ngan
Ngan = Val(Right$(PhanChan, 3))
PhanChan = Left$(PhanChan, Len(PhanChan) - Len(Trim$(Str$(Ngan))))
Case 3 'Trieu
Trieu = Val(Right$(PhanChan, 3))
PhanChan = Left$(PhanChan, Len(PhanChan) - Len(Trim$(Str$(Trieu))))
Case 4 'Ty
Ty = Val(Right$(PhanChan, 3))
PhanChan = Left$(PhanChan, Len(PhanChan) - Len(Trim$(Str$(Ty))))
Case 5 'Ngan Ty
NganTy = Val(Right$(PhanChan, 3))
PhanChan = Left$(PhanChan, Len(PhanChan) - Len(Trim$(Str$(NganTy))))
End Select
I = I + 1
Wend
If NganTy = 0 And Ty = 0 And Trieu = 0 And Ngan = 0 And Dong = 0 Then
BangChu = "không"
I = 5
Else
BangChu = ""
I = 0
End If
While I <= 5
Select Case I
Case 0
SoDoi = NganTy
Ten = "ngàn t?"
Case 1
SoDoi = Ty
Ten = "t?"
Case 2
SoDoi = Trieu
Ten = "tri?u"
Case 3
SoDoi = Ngan
Ten = "ngàn"
Case 4
SoDoi = Dong
Ten = ""
Case 5
SoDoi = SoLe
Ten = ""
End Select
If SoDoi <> 0 Then
Tram = Int(SoDoi / 100)
Muoi = Int((SoDoi - Tram * 100) / 10)
DonVi = (SoDoi - Tram * 100) - Muoi * 10
BangChu = BangChu + IIf(Tram <> 0, CharVND(Tram) + " tram ", "")
If Muoi = 0 And Tram <> 0 And DonVi <> 0 Then
BangChu = BangChu
Else
If Muoi <> 0 Then
BangChu = BangChu + IIf(Muoi <> 0 And Muoi <> 1, CharVND(Muoi) + "m" & ChrW$(432) & ChrW$(7901) & "i" & Space(1), "m" & ChrW$(432) & ChrW$(7901) & "i" & Space(1))
End If
End If
If Muoi <> 0 And DonVi = 5 Then
BangChu = BangChu + "lam " + Ten + " "
Else
If Muoi <> 0 And Muoi <> 1 And DonVi = 1 Then
BangChu = BangChu + "m?t " + Ten + " "
Else
BangChu = BangChu + IIf(DonVi <> 0, CharVND(DonVi) + " " + Ten + " ", Ten + " ")
End If
End If
Else
BangChu = BangChu + IIf(I = 4, "", "")
End If
I = I + 1
Wend
If SoLe = 0 Then
BangChu = BangChu
End If
Mid$(BangChu, 1, 1) = UCase$(Mid$(BangChu, 1, 1))
SoRaChu = BangChu
End Function
» Tin mới nhất:
» Các tin khác: