Option Explicit
Private Sub UserForm_Activate()
TextBox1.Value = 0: formate TextBox1
TextBox2.Value = 0: formate TextBox2
End Sub
'dans l'event update on appelle la sub formate
Private Sub TextBox1_AfterUpdate(): formate TextBox1: End Sub
Private Sub TextBox2_AfterUpdate(): formate TextBox2: End Sub
'dans l' event up on selectionne tout le contenu du textbox par la sub generiqus "completDelect"
Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
completSelecT TextBox1
End Sub
Private Sub TextBox2_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
completSelecT TextBox2
End Sub
'-------------------------------------------------------------------------------------------------------
'les subs generiques
Sub completSelecT(TXTB)
With TXTB: .SelStart = 0: .SelLength = 100: End With
End Sub
Sub formate(TXTB)
TXTB.Value = Format(Replace(TXTB.Value, ".", ","), "# ##0.00 €")
End Sub
'-------------------------------------------------------------------------------------------------------
'validation
Private Sub CommandButton1_Click()
With ActiveSheet
.[B5] = CDbl(TextBox1.Value)
.[E5] = CDbl(TextBox2.Value)
.[H5] = CDbl(TextBox1.Value) + CDbl(TextBox2.Value)
End With
Unload Me
End Sub