Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 在列表框中列出已筛选的选择_Excel_Vba - Fatal编程技术网

Excel 在列表框中列出已筛选的选择

Excel 在列表框中列出已筛选的选择,excel,vba,Excel,Vba,我只想在列表框中列出过滤后的选择,除了我不确定要加载到列表框中的内容外,其他一切都正常。这是我的密码 Private Sub btnRechercher_Click() Application.ScreenUpdating = False lstMoyens.Clear Sheets("TEST1").Select Range("Tableau4[[#Headers],[Famille]]").Select ActiveSheet.ListObjects

我只想在列表框中列出过滤后的选择,除了我不确定要加载到列表框中的内容外,其他一切都正常。这是我的密码

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
这对你有用

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

将RangeSelection,Selection.EndxlDown.Select更改为RangeSelection,Selection.EndxlDown.SpecialCellsxlCellTypeVisible.Select仅选择可见项太棒了!多谢各位much@Adach1979,短而准确。我认为你应该把它作为一个答案。至少我会投赞成票。