#NAME? error when trying to use a custom function!

BakirDZ

New Member
Joined
Sep 7, 2023
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
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?

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
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Most of your variables are not declared? :(

When I remove Option Explicit, it works for me, I think?

I just changed the name to chiff, as I was not going to type in the full name. Likely you have a typo?

1706358554784.png
 
Last edited:
Upvote 0
Most of your variables are not declared? :(

When I remove Option Explicit, it works for me, I think?

I just changed the name to chiff, as I was not going to type in the full name. Likely you have a typo?

View attachment 105851
Thank you I appreciate your help welshgasman,
I actually don't know how to declare every variable in this code

in the Youtube Video (start at 3:25) he copy pasted the exact same code I posted in my original post and it worked without changing anything..

a typo, no I don't think so cuz I type only few letters then scroll down to the function and press TAB..
 
Upvote 0
You Dim them with the correct data type.
Like you did here
Dim a As Variant, gros As Variant

I started adding them as they were declared as not defined, but gave up after three variables.
Can you send a link to your workbook? I do not think you an attach files here?
 
Upvote 0
The only way I can get a #NAME in the cell is to mistype the function name.
You did put it in a General module didn't you?, however if it is shown to you in the dropdown, then it must be found?
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top