Bonjour Mody,
Quelques modifications mineures... avec saisie obligatoire. Code à mettre dans l'userform. Question : Pourquoi faire référence à la cellule A1 ?
'Dans cet exemple, on utilise une variable booléenne pour stocker si toutes les Textbox
'sont remplies ou non.
'On utilise une instruction “Exit Sub” pour sortir de la macro si la Textbox 5 est vide.
Private Sub CommandButton3_Click()
Dim isFilled As Boolean
isFilled = True
If TextBox1.Value = "" Then
isFilled = False
End If
If TextBox2.Value = "" Then
isFilled = False
End If
If TextBox6.Value = "" Then
isFilled = False
End If
If TextBox7.Value = "" Then
isFilled = False
End If
If Not isFilled Then
MsgBox "Veuillez remplir toutes les TextBox avant de lancer le calcul"
Exit Sub
End If
'Quantité de carton = carton + pièce / nombre d'unités
'Pièce = quantité de pièce mod / nombre d'unités
If TextBox5.Value <> 0 Then
TextBox3.Value = Val(TextBox1.Value) + Int(Val(TextBox2.Value) / TextBox5.Value * 100)
TextBox4.Value = TextBox2.Value Mod TextBox5.Value
Else
MsgBox "Textbox5 vide"
Exit Sub
End If
TextBox3.Value = TextBox3.Value - TextBox4.Value
'Quantité de carton = carton + pièce / nombre d'unités
TextBox8.Value = Val(TextBox6.Value) + Int(Val(TextBox7.Value) / TextBox5.Value * 100)
'Pièce = quantité de pièce mod / nombre d'unités
TextBox9.Value = TextBox7.Value Mod TextBox5.Value
TextBox8.Value = TextBox8.Value - TextBox9.Value
End Sub
Private Sub CommandButton4_Click()
Dim i%
For i = 1 To 4
Me.Controls("textbox" & i) = ""
Next i
For i = 6 To 9
Me.Controls("textbox" & i) = ""
Next i
End Sub
Private Sub UserForm_Initialize()
TextBox1.SetFocus
UserForm1.TextBox5.Value = Sheet1.Range("A1")
End Sub