Catégories
Macro VBA Format Macros VBA

VBA FormatNumber() : macro pour formater sous forme de nombre

Partager :

La fonction FormatNumber dans VBA est utilisée pour formater sous forme de nombre.

La fonction FormatNumber

La fonction VBA FormatNumber suit la syntaxe suivante :

FormatNumber(variable)

Exemple de macro avec FormatNumber

La macro

Sub nommacro()

Dim i As Integer

For i = 1 To 5

'Résultat dans Ligne de 1 à 5, Colonne 2
Cells(i, 2).Value = Formatnumber(Cells(i, 1))

Next i

End Sub

Les données sources

ABCDE
111 200,00%
23 733,33%
31 244,44%
4414,81%
5138,27%

Le résultat

ABCDE
111 200,00%112,00
23 733,33%37,33
31 244,44%12,44
4414,81%4,15
5138,27%1,38