Affichage des nombres comme des mots dans Excel
category Ordinateurs et logiciels / Microsoft Office / Exceller
Si vous avez déjà eu besoin d'afficher un nombre écrit en tant que texte, vous avez probablement découvert que Excel ne propose pas une telle fonction. Lorsque Excel ne parvient pas à livrer, il est souvent possible de corriger le déficit en utilisant VBA. Voici une fonction VBA, nommé SPELLDOLLARS
Sommaire
Exemples Excel
Voici quelques exemples de SPELLDOLLARS.
Le code VBA
Pour utiliser ce code, appuyez sur Alt + F11 pour activer Visual Basic Editor. Ensuite, choisissez Insertion - Module pour insérer un nouveau module VBA. Copiez le code et collez-le dans le nouveau module.
Fonction SPELLDOLLARS (cellulaires) As Variant 'retourne une valeur, énoncé dans wordsDim Dollars As String, Cents Comme StringDim TextLen As Long, Pos Comme LongDim Temp Comme StringDim iHundreds As Long, itens As Long, Iones tant Ones LongDim Comme variante, Ados Comme Variant, des dizaines Comme VariantDim parts (2 à 5) Comme StringDim Bhit As Boolean, NegFlag As Boolean 'Est-ce un non-nombre ou cellule vide? Si Non IsNumeric (cellulaire) ou de la cellule = ThenSPELLDOLLARS = CVErr (xlErrValue) Quitter FunctionEnd Si «Est-il négatif? Si la cellule lt; 0 = ThenNegFlag Truecell = IfDollars Abs (cellulaire) Fin = Format (cellule, ### 0.00 ) TextLen = Len (en dollars) - 3 'est-ce trop grande Si TextLen> 15 ThenSPELLDOLLARS = CVErr (xlErrNum) Quitter FunctionEnd Si? «Faire le cents partCents = droite (Dollars, 2) / 100 Dollars Si la cellule lt; 1 = ThenSPELLDOLLARS CentsExit FunctionEnd IfDollars = Gauche (Dollars, TextLen) Ones = Array ( # 147 ;, ;, Une ;, Deux ;, Trois Four ;, _ ;, Cinq ;, Six ;, Seven ;, Huit Nine ) Teens = Array ( ;, Ten ;, Eleven ;, Douze ;, Treize ;, Quatorze _ ;, Quinze ;, Seize ;, Seventeen ;, Eighteen Nineteen ) Des dizaines = Array ( # 147 ;, # 147 ;, ;, Vingt ;, Trente ;, Quarante ;, Cinquante _ ;, Soixante ;, Soixante ;, Eighty Ninety ) Unités (2) = Mille unités (3) = Million Units (4) = Billion unités (5) = Trillion Temp = pour les OP = 15 à 3 Étape -3If TextLen> = Pos - 2 ThenbHit = FalseIf TextLen> = Pos TheniHundreds = Asc (Mid $ (Dollars, TextLen - Pos + 1, 1)) - 48Si iHundreds> 0 ThenTemp = Temp Ones (iHundreds) Cent Bhit = TrueEnd IfEnd IfiTens = 0iOnes = 0 si TextLen> = POS - 1 TheniTens = Asc (Mid $ (Dollars, TextLen - Pos + 2, 1)) - 48End IFIF TextLen> = Pos - 2 TheniOnes = Asc ( Mid $ (Dollars, TextLen - Pos + 3, 1)) - 48End IFIF itens = 1 ThenTemp = Temp Teens (Iones) Bhit = TrueElseIf itens> = 2 ThenTemp = Temp Des dizaines (itens) Bhit = TrueEnd IFIF Iones> 0 ThenIf itens> = 2 ThenTemp = Temp - ElseTemp = Temp Fin IfTemp = Temp Ones (Iones) Bhit = TrueEnd IfEnd IFIF Bhit Et Pos> 3 ThenTemp = Temp Unités (Pos 3) Fin IfEnd IfNext PosSPELLDOLLARS = trim (Temp) et CentsIf NegFlag Puis SPELLDOLLARS = ( SPELLDOLLARS ) End Function