Bonjour,
le problème vient du code que j'ai surligné. en initialisant des éléments d'un userform tu déclenches l'évènement change et s'il existe une procédure change associée à cet élément elle est déclenchée. c'est ce qui ce passe avec textbox1 quant tu le remets à "". textbox1_change est exécuté et comme textbox1 est "", tu as une erreur 13 lors de la conversion de date.
il faut soit desactiver les events, soit positionner une variable que tu testes au début de chaque procédure change en fonction de ce que tu es en train de faire, par exemple v="initialize" quand tu vas initialiser et mettre comme première instruction dans tes procédures change if v="initialize" then exit sub
Private Sub CommandButton3_Click()
Dim i As Integer 'saisie obligatoire
For i = 1 To 3
If i <> 5 And i <> 6 Then
If Me("TextBox" & i) = "" Then
Me("TextBox" & i).SetFocus
MsgBox "La saisie de tous les champs est obligatoire"
Exit Sub
End If
End If
Next i
For i = 1 To 4
If Me("ComboBox" & i) = "" Then
Me("ComboBox" & i).SetFocus
MsgBox "La saisie de tous les champs est obligatoire"
Exit Sub
End If
Next i
Dim Ligne As Long
Dim Cel As Range
CommandButton3.Caption = "valider"
CommandButton3.Default = True
With Sheets("mouvements")
Set Cel = .Columns("H").Find(what:=Me.ComboBox4, LookIn:=xlValues, lookat:=xlWhole)
If Not Cel Is Nothing Then
Ligne = Cel.Row
'Prochaine ligne disponible
'NewLine = .Range("k" & .Rows.Count).End(xlUp)(2).Row
.Range("K" & Ligne) = CDate(TextBox1)
.Range("L" & Ligne) = TextBox2
.Range("M" & Ligne) = ComboBox1.Value
.Range("N" & Ligne) = ComboBox2.Value
.Range("O" & Ligne) = TextBox4
.Range("Q" & Ligne) = CDbl(TextBox3)
.Range("T" & Ligne) = ComboBox3.Value
End If
Dim C As Control
For Each C In Me.Controls 'remise à zéro USF
Select Case TypeName(C)
Case "TextBox"
C.Value = ""
Case "CheckBox"
C.Value = False
Case "ListBox", "ComboBox"
C.ListIndex = -1
End Select
Next C
End With
'InitCBB4
End Sub