Dans l'userform, remplacez le code que je vous ai donné par celui ci-dessous
Private Sub CommandButton1_Click()
Dim ligne As Integer
Dim i As Byte
For i = 1 To 8
If Controls("Textbox" & i) = "" Then
MsgBox "Champ " & Controls("Label" & i) & " Obligatoire", , "Alerte"
Controls("Textbox" & i).SetFocus
Exit Sub
End If
Next i
With Sheets("achat")
ligne = .Range("A" & .Rows.Count).End(xlUp).Row + 1
.Range("A" & ligne) = TextBox1.Value 'Article
.Range("B" & ligne) = CCur(TextBox2.Value) 'prix achat
.Range("C" & ligne) = CCur(TextBox3.Value) 'transport
.Range("D" & ligne) = CCur(TextBox4.Value) 'douane
.Range("E" & ligne) = CDate(TextBox5.Value) 'date achat
.Range("F" & ligne) = CDate(TextBox6.Value) 'date livraison
.Range("G" & ligne) = TextBox7.Value 'fournisseur
.Range("H" & ligne) = TextBox8.Value 'pays
End With
Call Reset
If MsgBox("Souhaitez-vous enregistrer un autre article ?", vbYesNo + vbDefaultButton2, "Enregistrer article") = vbYes Then
Else: Unload UserForm1
End If
End Sub
- Toujours dans l'userform, rajouter celui ci-dessous pour vider l'userform
Sub Reset()
Dim i As Byte
For i = 1 To 8
Controls("Textbox" & i) = ""
Next i
End Sub
Cordialement