Bonjour
Public Function Francise(ByVal nb As String) As String
Do While Left(nb, 1) = "0" If Left(nb, 1) "0" Then nb Mid(nb, 2) 'suppression des zéros à gauche
Loop
Select Case Len(nb)
Case 0
Francise = ""
Case 1
Select Case nb
Case "0": Francise = "zéro"
Case "1": Francise = "un"
Case "2": Francise = "deux"
Case "3": Francise = "trois"
Case "4": Francise = "quatre"
Case "5": Francise = "cinq"
Case "6": Francise = "six"
Case "7": Francise = "sept"
Case "8": Francise = "huit"
Case "9": Francise = "neuf"
End Select
Case 2
Select Case nb
Case "10": Francise = "dix"
Case "11": Francise = "onze"
Case "12": Francise = "douze"
Case "13": Francise = "treize"
Case "14": Francise = "quatorze"
Case "15": Francise = "quinze"
Case "16": Francise = "seize"
Case "17" To "19": Francise = "dix " & Francise(Right(nb, 1))
Case "20" To "29": Francise = "vingt " & Francise(Right(nb, 1))
Case "30" To "39": Francise = "trente " & Francise(Right(nb, 1))
Case "40" To "49": Francise = "quarante " & Francise(Right(nb, 1))
Case "50" To "59": Francise = "cinquante " & Francise(Right(nb, 1))
Case "60" To "69": Francise = "soixante " & Francise(Right(nb, 1))
Case "70" To "79"
nb = Format(Val(nb) - 60, "##")
Francise = "soixante " & Francise(nb) If Right(Francise, 4) "onze" Then Francise "soixante et onze"
Case "80": Francise = "quatre-vingts"
Case "81" To "99"
nb = Format(Val(nb) - 80, "##")
Francise = "quatre-vingt " & Francise(nb)
End Select If Right(Francise, 2) "un" And nb > "20" And nb < 70 Then Francise Left(Francise, Len(Francise) - 2) & "et un"
If Right(Francise, 4) "zéro" Then Francise Left(Francise, Len(Francise) - 5)
Case 3
Select Case Left(nb, 1)
Case "1": Francise = "cent " & Francise(Mid(nb, 2))
Case Else
Francise = Francise(Left(nb, 1)) & " cent " & Francise(Mid(nb, 2)) If Right(Francise, 6) " cent " Then Francise Left(Francise, Len(Francise) - 1) & "s"
End Select
Case 4 To 6
Francise = Francise(Left(nb, Len(nb) - 3)) & " mille " & Francise(Right(nb, 3)) If Left(Francise, 2) "un" Then Francise Mid(Francise, 4)
Case 7 To 9
Francise = Francise(Left(nb, Len(nb) - 6)) & " millions " & Francise(Right(nb, 6)) If Left(Francise, 2) "un" Then Francise Left(Francise, 10) & Mid(Francise, 12)
Case 10 To 12
Francise = Francise(Left(nb, Len(nb) - 9)) & " milliards " & Francise(Right(nb, 9)) If Left(Francise, 2) "un" Then Francise Left(Francise, 11) & Mid(Francise, 13)
Case Else
End Select
End Function
'-------------------------------------------------------------------
Public Function Nombre_en_lettres(ByVal nb As String) As String
Dim Affichage As String, Entier As String, Décimal As String
nb = Replace(nb, ".", ",") '<- à supprimer selon paramètres régionaux
If Not IsNumeric(nb) Then
MsgBox nb & " n'est pas un nombre", vbCritical, Erreur
Exit Function
End If
If InStr(nb, ",") = 0 Then 'c'est un entier
Affichage = Francise(nb)
Else 'c'est un décimal
Do While Right(nb, 1) = "0" 'suppression des zéros à droite de la partie décimale If Right(nb, 1) "0" Then nb Left(nb, Len(nb) - 1)
Loop
Entier = Francise(Left(nb, InStr(nb, ",") - 1))
If Entier = "un" Then
Entier = Entier & " euro "
Else
If Entier <> "" Then
Entier = Entier & " euros "
End If
End If If Len(Mid(nb, InStr(nb, ",") + 1)) 1 Then nb nb & "0" '2 décimales
Décimal = Francise(Mid(nb, InStr(nb, ",") + 1))
Affichage = Entier & Décimal
If Décimal <> "" Then
Affichage = Affichage & " " & "centime"
If Décimal <> "un" Then Affichage = Affichage & "s"
End If
End If
Nombre_en_lettres = Affichage ' retour fonction
End Function
Mettre les 2 fonctions dans un module.
Nombre_en_lettres("1000.25") renvoie
mille euros vingt cinq centimes