列出ListBox中的筛选选择

时间:2014-06-05 11:20:09

标签: excel-vba vba excel

我想在ListBox中仅列出已过滤的选择,一切正常,但我不确定要加载到ListBox中的内容。这是我的代码

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

1 个答案:

答案 0 :(得分:0)

这对你有用

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