Re,
Honnêtement, c'est compliqué pour moi de vous renvoyer le fichier, les userforms ne sont pas vraiment ma tasse de thé et il y a trop de modifications à faire...
Je vous propose un code à placer dans un module normal :
Sub test()
Dim ctrl As Control, tfiltre()
With Sheets("bdd1").Range("BDD")
t = .Resize(, .Columns.Count - 1)
ReDim tfiltre(1 To UBound(t, 2), 1 To UBound(t))
For i = LBound(t) To UBound(t)
retenir = True
For Each ctrl In SuiviCommande.Controls
partnom = Split(ctrl.Name, "_")
If UBound(partnom) > 1 Then
If (partnom(0) = "txt" Or partnom(0) = "cbx") And partnom(1) = "Rech" Then
verif = False
col = Application.Match(partnom(2), .Rows(0), 0)
If CStr(t(i, col)) Like "*" & ctrl.Value & "*" Then verif = True
retenir = retenir And verif
End If
End If
Next ctrl
If retenir Then
n = n + 1
For j = LBound(t, 2) To UBound(t, 2)
tfiltre(j, n) = t(i, j)
Next j
End If
Next i
End With
With SuiviCommande.LBxRecherche
.Clear
If n > 0 Then
.ColumnCount = UBound(t, 2)
ReDim Preserve tfiltre(1 To UBound(t, 2), 1 To n)
If n = 1 Then
.Column = tfiltre
Else
.List = Application.Transpose(tfiltre)
End If
End If
End With
End Sub
Il faut :
- mettre le tableau de "bdd1" sous forme de tableau structuré et le nommer "BDD",
- renommer les colonnes et les contrôles correspondants ainsi (en tout cas, sur ce modèle) (type[repris dans le code]_Rech_nomdecolonne) :
Designation | txt_Rech_Designation |
Destinataire | txt_Rech_Destinataire |
Site | txt_Rech_Site |
Fournisseur | txt_Rech_Fournisseur |
Etat | cbx_Rech_Etat |
Service | cbx_Rech_Service |
NumDA | txt_Rech_NumDA |
DateDA | txt_Rech_DateDA |
DateValidation | txt_Rech_DateValidation |
NumBC | txt_Rech_NumBC |
DateBC | txt_Rech_DateBC |
dateCommande | txt_Rech_dateCommande |
DateLivraison | txt_Rech_DateLivraison |
- placer ensuite, pour chaque contrôle, au sein de la macro évènementielle Change() (ou beforeupdate() pour les combo) la simple instruction Call test.
On verra éventuellement ce qu'on peut faire pour les dates car je ne sais pas vraiment comment arbitrer.
Cdlt,