Problème avec mon probramme VBA
Résolu
novice53
Messages postés
5
Statut
Membre
-
pijaku Messages postés 13513 Statut Modérateur -
pijaku Messages postés 13513 Statut Modérateur -
Bonjour,
j'ai écrit un programme en VBA qui me permet de faire une approximation de mes nombres c-a-d
quand j'ai un nombre de 12.3000000 mon approximation me donne 12.3
mon problème est le suivant quand mon nombre est entier l'approximation de ce nombre est suivi d'une virgule
exemple: 90 approximation me donne 90,
quand j'ai un nombre entier sans decimal mon approximation me fait apparaitre la virgule derière ce nombre entier, chose que je veux pas
s'il vous plait quelqu'un pourrait me dire comment faire pour qu'elle n'apparait plus merci
j'ai écrit un programme en VBA qui me permet de faire une approximation de mes nombres c-a-d
quand j'ai un nombre de 12.3000000 mon approximation me donne 12.3
mon problème est le suivant quand mon nombre est entier l'approximation de ce nombre est suivi d'une virgule
exemple: 90 approximation me donne 90,
quand j'ai un nombre entier sans decimal mon approximation me fait apparaitre la virgule derière ce nombre entier, chose que je veux pas
s'il vous plait quelqu'un pourrait me dire comment faire pour qu'elle n'apparait plus merci
Function approximation(Point As String) As String
Dim approx As Double
If Val(Point) < 0 Then
approx = -0.0005
Else
approx = 0.0005
End If
Point = Str(Val(Point) + approx)
Point = Mid(Point, 1, InStr(Point, ".") + 3)
If InStr(Point, "-") = 1 Then
If InStr(Point, "") = 2 Then Point = "-0" + Mid(Point, 2, Len(Point))
Else
If InStr(Point, ".") = 1 Then Point = "0" + Point
End If
If InStr(Point, " ") = 1 Then
Point = Mid(Point, 1, Len(Point))
End If
If Right(Point, 4) = ".000" Then
Point = Left(Point, Len(Point) - 3)
End If
If Right(Point, 2) = "00" Then
Point = Left(Point, Len(Point) - 2)
End If
If Right(Point, 1) = "0" Then
Point = Left(Point, Len(Point) - 1)
End If
If Val(Point) = 0 Then Point = "0"
approximation = Point
End Function
A voir également:
- Problème avec mon probramme VBA
- Excel compter cellule couleur sans vba - Guide
- Vba attendre 1 seconde ✓ - Forum VB / VBA
- Dépassement de capacité vba ✓ - Forum Excel
- Incompatibilité de type vba ✓ - Forum VB / VBA
- Erreur 13 incompatibilité de type VBA excel ✓ - Forum Excel
merci pour ton aide, j' avais même pas pensé qu'il falait réécrire une nouvelle condition.
je suis débutant dans le language informatique, et j'apprend en faisant certaine programation.
l'intérêt de ma fonction est de ne plus utiliser le format de celule nombre d'excel mais le mien uniquement.
je fait beaucoup de calcul sur excel c'est our cette raison.
je te remerci pour ton aide
A+