Hello everyone, hope you are doing well..
I got the VBA code of this custom function from youtube and after I add a module and copy paste the code just like the video, I find the new function but when I use it it shows an error #NAME?
I got the VBA code of this custom function from youtube and after I add a module and copy paste the code just like the video, I find the new function but when I use it it shows an error #NAME?
VBA Code:
Dim Sh As Object
Function chiffrelettre(s)
Dim a As Variant, gros As Variant
a = Array("", "Un", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", _
"Huit", "Neuf", "Dix", "Onze", "Douze", "Treize", "Quatorze", "Quinze", "Seize", "Dix Sept", _
"Dix Huit", "Dix Neuf", "Vingt", "Vingt et Un", "Vingt Deux", "Vingt Trois", "Vingt Quatre", _
"Vingt Cinq", "Vingt Six", "Vingt Sept", "Vingt Huit", "Vingt Neuf", "Trente", "Trente et Un", _
"Trente Deux", "Trente Trois", "Trente Quatre", "Trente Cinq", "Trente Six", "Trente Sept", _
"Trente Huit", "Trente Neuf", "Quarante", "Quarante et Un", "Quarante Deux", "Quarante Trois", _
"Quarante Quatre", "Quarante Cinq", "Quarante Six", "Quarante Sept", "Quarante Huit", _
"Quarante Neuf", "Cinquante", "Cinquante et Un", "Cinquante Deux", "Cinquante Trois", _
"Cinquante Quatre", "Cinquante Cinq", "Cinquante Six", "Cinquante Sept", "Cinquante Huit", _
"Cinquante Neuf", "Soixante", "Soixante et Un", "Soixante Deux", "Soixante Trois", _
"Soixante Quatre", "Soixante Cinq", "Soixante Six", "Soixante Sept", "Soixante Huit", _
"Soixante Neuf", "Soixante Dix", "Soixante et Onze", "Soixante Douze", "Soixante Treize", _
"Soixante Quatorze", "Soixante Quinze", "Soixante Seize", "Soixante Dix Sept", _
"Soixante Dix Huit", "Soixante Dix Neuf", "Quatre-Vingts", "Quatre-Vingt Un", _
"Quatre-Vingt Deux", "Quatre-Vingt Trois", "Quatre-Vingt Quatre", "Quatre-Vingt Cinq", _
"Quatre-Vingt Six", "Quatre-Vingt Sept", "Quatre-Vingt Huit", "Quatre-Vingt Neuf", _
"Quatre-Vingt Dix", "Quatre-Vingt Onze", "Quatre-Vingt Douze", "Quatre-Vingt Treize", _
"Quatre-Vingt Quatorze", "Quatre-Vingt Quinze", "Quatre-Vingt Seize", "Quatre-Vingt Dix Sept", _
"Quatre-Vingt Dix Huit", "Quatre-Vingt Dix Neuf")
gros = Array("", "Billions", "Milliards", "Millions", "Mille", "Dinars", "Billion", _
"Milliard", "Million", "Mille", "Dinar")
sp = Space(1)
chaine = "00000000000000"
Centime = s * 100 - (Int(s) * 100)
s = Str(Int(s)): Lg = Len(s) - 1: s = Right(s, Lg): Lg = Len(s)
If Lg < 15 Then chaine = Mid(chaine, 1, (15 - Lg)) Else chaine = ""
s = chaine + s
'Billions au Centaines
gp = 1
For k = 1 To 5
x = Mid(s, gp, 1): c = a(Val(x))
x = Mid(s, gp + 1, 2): d = a(Val(x))
If k = 5 Then
If t2 <> "" And c & d = "" Then mydz = "Dinars" & sp: GoTo Fin
If t <> "" And c = "" And d = "Un" Then mydz = "Un Dinars" & sp: GoTo Fin
If t <> "" And t2 = "" And c & d = "" Then mydz = "de Dinars" & sp: GoTo Fin
If t & c & d = "" Then myct = "": mydz = "": GoTo Fin
End If
If c & d = "" Then GoTo Fin
If d = "" And c <> "" And c <> "Un" Then mydz = c & sp & "cents " & gros(k) & sp: GoTo Fin
If d = "" And c = "Un" Then mydz = "Cent " & gros(k) & sp: GoTo Fin
If d = "Un" And c = "" Then myct = IIf(k = 4, gros(k) & sp, "Un " & gros(k + 5) & sp): GoTo Fin
If d <> "" And c = "Un" Then mydz = "Cent" & sp
If d <> "" And c <> "" And c <> "Un" Then mydz = c & sp & "Cent" + sp
myct = d & sp & gros(k) & sp
Fin:
t2 = mydz & myct
t = t & mydz & myct
mydz = "": myct = ""
gp = gp + 3
Next
d = a(Centime)
If t <> "" Then myct = IIf(Centime = 1, " Centime", " Centimes")
If t = "" Then myct = IIf(Centime = 1, " Centime de Dinar", " Centimes de Dinar")
If Centime = 0 Then d = "": myct = ""
chiffrelettre = t & d & myct
End Function