List filtered selection in ListBox
Question
I would like to list only filtred selections in a ListBox, everything works except I am not sure what to load into the ListBox. This my code
Private Sub btnRechercher_Click()
Application.ScreenUpdating = False
lstMoyens.Clear
Sheets("TEST1").Select
Range("Tableau4[[#Headers],[Famille]]").Select
ActiveSheet.ListObjects("Tableau4").Range.AutoFilter Field:=4, Criteria1:="=" & cbFamille.SelText, Operator:=xlAnd
Range("B1:C1").Select
Range(Selection, Selection.End(xlDown)).Select
Dim r As Range
For Each r In Selection.Rows
lstMoyens.AddItem (r.Cells(3) & " : " & r.Cells(4))
Next r
End Sub
Solution
This will work for you
Private Sub btnRechercher_Click()
Application.ScreenUpdating = False
lstMoyens.Clear
Sheets("TEST1").Select
Range("Tableau4[[#Headers],[Famille]]").Select
ActiveSheet.ListObjects("Tableau4").Range.AutoFilter Field:=4, Criteria1:="=" & cbFamille.SelText, Operator:=xlAnd
Range("B1:C1").Select
Range(Selection, Selection.End(xlDown)).SpecialCells(xlCellTypeVisible).Select
Dim r As Range
For Each r In Selection.Rows
lstMoyens.AddItem (r.Cells(3) & " : " & r.Cells(4))
Next r
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow