2014-06-05 48 views
0

我想僅列出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

變化'範圍(選擇,Selection.End(xlDown))。Select'爲'範圍(選擇,Selection.End(xlDown)) .SpecialCells(xlCellTypeVisible).Select'選擇僅可見 – Adach1979

+0

太棒了!非常感謝你 – user3710873

+0

@ Adach1979,簡短但現貨。我認爲你應該把它作爲答案。我至少會投票。 –

回答

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