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
| Private Sub produitfiltre()
Dim Plage As Range, Cel As Range
Dim produit
Dim ERREUR
With Sheets("feuil1")
If .AutoFilterMode Then 'vérifie si le filtre automatique est actif et
.AutoFilterMode = False 'l'enlève
End If
produit = TextBoxproduitcherche 'valeur entrée dans un textbox pour alimenter le filtre
ERREUR = .Range("a2").End(xlDown).Offset(0, 0).Row 'variable donnant le n° de la dernière lg à filtrer
.Range("c2").AutoFilter
.Range("c2").AutoFilter Field:=3, Criteria1:="*" & produit & "*" 'applique le filtre
Set Plage = .Range("g2", .Range("g2").End(xlDown))
Set Plage = Plage.Cells.SpecialCells(xlCellTypeVisible) 'tableau avec données filtrées
If Plage.Count > ERREUR Then 'eviter de renvoyer une erreur ou un bug
If .AutoFilterMode Then
.AutoFilterMode = False
Exit Sub 'pour un filtre non trouvé
End If
ListBoxPRODUITS.Clear 'vide la listbox
For Each Cel In Plage 'et la réalimente
With ListBoxPRODUITS
.AddItem Cel(1, -3)
.Column(1, .ListCount - 1) = Format(Cel(1, -2), "#,##0.00 ")' format a changer suivant besoin
.Column(2, .ListCount - 1) = Format(Cel(1, 0), "#,##0.00 ")' format a changer suivant besoin
.Column(3, .ListCount - 1) = Format(Cel(1, 4), "#,##0.00 ")' format a changer suivant besoin
.Column(4, .ListCount - 1) = Format(Cel(1, 5), "###0")' format a changer suivant besoin
.Column(5, .ListCount - 1) = Cel(1, 1)
End With
Next Cel
Selection.AutoFilter 'enlève le filtre de la feuille
End With
End Sub |
Partager