XL 2016 Soustraction avec format monétaire dans textbox

dindin

XLDnaute Occasionnel
Bonjour,
j'ai 3 textbox, soit:

VB:
TextBox3.Value = Val(TextBox1.Value) - Val(TextBox2.Value)

1629295606508.png

en utilisant le . la soustraction fonctionne bien.
le souci c'est quand je remplace le point par une virgule :(voir photo)
1629295728784.png

- Comment peut-on remédier à ce problème de format?
j'utilise ce code pour essayer de forcer le format monétaire dans une textbox mais ce code ne fonctionne pas :

Code:
'Private Sub TextBox1_Change()
'Me.TextBox1.Value = Format(Me.TextBox1.Value, "# ##0.00 €")
'End Sub
'
'Private Sub TextBox2_Change()
'Me.TextBox2.Value = Format(Me.TextBox2.Value, "# ##0.00 €")
'End Sub
'
'Private Sub TextBox3_Change()
'Me.TextBox3.Value = Format(Me.TextBox3.Value, "# ##0.00 €")
'End Sub
Merci pour votre aide
je joins le fichier
 

Pièces jointes

  • format monétaire.xlsm
    18.1 KB · Affichages: 15

job75

XLDnaute Barbatruc
Bonjour dindin,

Avec ce code dans l'UserForm il n'y a pas besoin du bouton :
VB:
Private Sub TextBox1_Change()
TextBox3 = Format(Val(Replace(TextBox1, ",", ".")) - Val(Replace(TextBox2, ",", ".")), "# ##0.00 €")
End Sub

Private Sub TextBox2_Change()
TextBox1_Change
End Sub

Private Sub TextBox1_AfterUpdate()
TextBox1 = Format(Val(Replace(TextBox1, ",", ".")), "# ##0.00 €")
End Sub

Private Sub TextBox2_AfterUpdate()
TextBox2 = Format(Val(Replace(TextBox2, ",", ".")), "# ##0.00 €")
End Sub
A+
 

richi2casa

XLDnaute Nouveau
Bonjour dindin,

Avec ce code dans l'UserForm il n'y a pas besoin du bouton :
VB:
Private Sub TextBox1_Change()
TextBox3 = Format(Val(Replace(TextBox1, ",", ".")) - Val(Replace(TextBox2, ",", ".")), "# ##0.00 €")
End Sub

Private Sub TextBox2_Change()
TextBox1_Change
End Sub

Private Sub TextBox1_AfterUpdate()
TextBox1 = Format(Val(Replace(TextBox1, ",", ".")), "# ##0.00 €")
End Sub

Private Sub TextBox2_AfterUpdate()
TextBox2 = Format(Val(Replace(TextBox2, ",", ".")), "# ##0.00 €")
End Sub
A+
Private Sub Calculer_Click()
TextBox3 = Format(Val(Replace(TextBox1, ",", ".")) - Val(Replace(TextBox2, ",", ".")), "# ##0.00 €")
End Sub


Private Sub TextBox1_AfterUpdate()
TextBox1 = Format(Val(Replace(TextBox1, ",", ".")), "# ##0.00 €")
End Sub

Private Sub TextBox2_AfterUpdate()
TextBox2 = Format(Val(Replace(TextBox2, ",", ".")), "# ##0.00 €")
End Sub
 

Discussions similaires

Réponses
17
Affichages
249
Réponses
16
Affichages
447
Réponses
5
Affichages
365
Réponses
12
Affichages
393

Statistiques des forums

Discussions
311 720
Messages
2 081 907
Membres
101 836
dernier inscrit
karmon