Ok on passe au suivant
1. Au dessus de tous les codes, mettez ces deux instructions
Option Compare Text
Dim col As Byte
2. Ajoutez ce code qui sera exécuté au changement de la combobox
Private Sub ComboBox1_Change()
col = ComboBox1.ListIndex + 2
TextBox1 = vbNullString
Call init
End Sub
3. Ajoutez ce code pour la textbox1 dans laquelle vous allez entrer votre recherche
Private Sub TextBox1_AfterUpDate()
If ComboBox1.Value = vbNullString Then
MsgBox ("Veuillez choisir un critère de recherche dans la liste déroulante"), vbInformation, "Information"
TextBox1.Value = vbNullString
End If
End Sub
4. Ajoutez ce code qui sera exécuté au click du bouton Rechercher
Private Sub btnRechercher_Click()
Dim tablo()
Dim n As Integer, i As Integer
Dim k As Byte
Dim lig
lstDossier.Clear
If TextBox1 = vbNullString Then Call init: Exit Sub
With ThisWorkbook.Worksheets("Base").ListObjects(1) '.ListColumns(3)
n = .DataBodyRange.Rows.Count
ReDim tablo(1 To n, 1 To .DataBodyRange.Columns.Count)
lig = 0
For i = 1 To n
If .DataBodyRange(i, col).Value Like "*" & TextBox1.Value & "*" Then
lig = lig + 1
For k = 1 To .DataBodyRange.Columns.Count
tablo(lig, k) = .DataBodyRange(i, k).Value 'Cells(i + 1, k)
Next k
End If
Next i
lstDossier.List = tablo()
End With
'supprimer les lignes vides dans listbox
For i = lstDossier.ListCount - 1 To 0 Step -1
If lstDossier.List(i, col) = "" Then lstDossier.RemoveItem (i)
Next i
txtTotal = lig
End sub
Faites un test et dites-moi
Rem : à quoi va vous servir le code Private Sub btnAjouter_Click() ?