1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Private Sub Search_Click()
Dim Ind As Integer, DLig As Long, Lig As Long
Dim TabCrit() As String, NbCrit As Integer, NbFind As Integer
' Tableau des champs pas rapport au sens des colonnes
TabCrit = Split("texte,type_matière,forme,diametre", ",")
' Effacer la ListBox avant
Me.ListBox1.Clear
' Avec la feuille
With Sheets("BDD_MP")
' Mémoriser la dernière ligne remplie du tableau
DLig = .Range("B" & Rows.Count).End(xlUp).Row
' Pour chaque ligne
For Lig = 2 To DLig
' Mettre le nombre de critères et le nombre de valeurs trouvées à ZERO
NbCrit = 0: NbFind = 0
' Pour chaque critère
For Ind = 0 To 4
' Si le critère de recherche a été renseigné
If Me.Controls(TabCrit(Ind)) <> "" Then
NbCrit = NbCrit + 1
' Si le critère ressemble au contenu de la cellule
If UCase(.Cells(Lig, 2 + Ind)) Like UCase("*" & Me.Controls(TabCrit(Ind)) & "*") Then
' Comptabiliser le nombre de valeurs correspondantes
NbFind = NbFind + 1
End If
End If
Next Ind
' Si le nombre de critères rempli = le nombre de valeurs trouvées
If NbCrit = NbFind Then
' Ajouter l'item
Me.ListBox1.AddItem .Cells(Lig, 2)
' Pour chaque colonne
'For Ind = 1 To 7
' Ajouter les valeurs correspondantes
' Me.ListBox1.List(Me.ListBox1.ListCount - 1, Ind) = .Cells(Lig, 2 + Ind)
'Next Ind
End If
Next Lig
End With
End Sub |
Partager