Bonjour,
J'ai créé un USF avec des textbox. Je viens d'y ajouter un combobox. Depuis, je rencontre un problème quand je souhaite valider. Le débogage s'effectue sur cette ligne :
.Cells(Ln, i).Value = Controls("TextBox" & i)
Je vous joins le code pour initialiser le USF et celui de la commande valider.
Private Sub UserForm_Initialize()
TextBox1.Text = CStr(Date)
TextBox18.Text = CStr(Date)
With Worksheets("Feuil2")
DerLn = .Range("A" & Rows.Count).End(xlUp).Row
For Ln = 2 To DerLn
If .Cells(Ln, "E").Value = "" And .Cells(Ln, "F").Value = "" And .Cells(Ln, "H").Value = "" And .Cells(Ln, "I").Value = "" And .Cells(Ln, "J").Value = "" _
And .Cells(Ln, "K").Value = "" And .Cells(Ln, "L").Value = "" And .Cells(Ln, "M").Value = "" _
And .Cells(Ln, "N").Value = "" And .Cells(Ln, "O").Value = "" And .Cells(Ln, "P").Value = "" _
And .Cells(Ln, "Q").Value = "" And .Cells(Ln, "R").Value = "" Then
Cbb_Factures.AddItem .Cells(Ln, "C").Value
'Cbb_Factures.ListIndex = Cbb_Factures.ListCount - 1
End If
Next Ln
End With
ComboBoxdestination.AddItem "A2COM"
ComboBoxdestination.AddItem "A2FP"
ComboBoxdestination.AddItem "A2IST"
End Sub
Private Sub Cmd_Valider_Click()
If Cbb_Factures = TextBox3 Then
Flag = 1
Else
Flag = 0
End If
With Worksheets("Feuil2")
If TextBox5 = "" And TextBox6 = "" And TextBox8 = "" And TextBox9 = "" _
And TextBox10 = "" And TextBox11 = "" And TextBox12 = "" And TextBox13 = "" And TextBox14 = "" _
And TextBox15 = "" And TextBox16 = "" And TextBox17 = "" Then
If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Or TextBox4 = "" Then
MsgBox "Saisie incomplète." & Chr(13) & _
"Vous devez saisir le nom du fournisseur, le n° de la facture et le montant HT.", 17
Exit Sub
End If
'On vérifie que la facture n'existe pas dèjà sur la feuille
Set cell = .Range("C2:C" & .Range("C1").End(xlDown).Row).Find(TextBox3, lookat:=xlWhole)
If Not cell Is Nothing Then
MsgBox " La facture " & TextBox3 & " a déjà été prise en compte.", 17
Exit Sub
End If
Ln = .Range("A" & Rows.Count).End(xlUp)(2).Row
For i = 1 To 4
.Cells(Ln, i).Value = Controls("TextBox" & i)
Next i
Else
Set cell = .Range("C2:C" & DerLn).Find(Cbb_Factures, lookat:=xlWhole)
If Not cell Is Nothing Then
Ln = cell.Row
For i = 1 To 18
.Cells(Ln, i).Value = Controls("TextBox" & i)
Controls("TextBox" & i) = ""
Next i
End If
End If
MsgBox "Les données de la facture " & .Cells(Ln, "C").Value & " ont été prises en compte."
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox1.Text = CStr(Date)
End With
End Sub
Merci pour votre aide.