Bonsoir MICKAEL59 , LouReeD ,
Pour ce que j'en ai compris, voir le fichier joint. Il est basé sur une nouvelle fonction AlimenterListbox.
Cette fonction comprend un paramètre optionnel filtre: Sub AlimenterListbox(Optional ByVal filtre)
- Si ref est absent alors on garni Listbox1 avec toutes les lignes de DC4
- Si ref est présent alors on filtre DC4 avec le champ Réf. Papyrus qui doit contenir filtre
- votre fonction initiale d'alimentation de Listbox1 a été supprimée
Le code de la fonction :
Sub AlimenterListbox(Optional ByVal filtre)
Dim der&, t
ListBox1.Clear
If IsMissing(filtre) Then filtre = "*"
If filtre = "" Then filtre = "*"
filtre = LCase(filtre)
With Sheets("DC4")
If .FilterMode Then .ShowAllData
der = .Cells(Rows.Count, "a").End(xlUp).Row
If der = 2 Then Exit Sub
t = .Range("a2:o" & der)
For i = 1 To UBound(t)
If LCase(t(i, 1)) Like "*" & filtre & "*" Then
n = n + 1
For j = 1 To UBound(t, 2): t(n, j) = t(i, j): Next
End If
Next i
If n > 0 Then
ReDim r(1 To n, 1 To UBound(t, 2))
For i = 1 To n: For j = 1 To UBound(t, 2): r(i, j) = t(i, j): Next j: Next i
Usf_DC4.ListBox1.List = r
End If
End With
End Sub
...