excel 如何使组合框依赖于过滤表?

yizd12fk  于 2023-05-19  发布在  其他
关注(0)|答案(1)|浏览(121)

我有下表:

表格可以通过命令按钮/用户表单进行过滤:

Sub standardfilter()

    Dim ws As Worksheet
    Dim tbl As ListObject
    
    Set ws = ActiveSheet
    Set tbl = ws.ListObjects("Tabelle1")
    
    With tbl.Range
        
        .AutoFilter field:=1, Criteria1:=Gremienauswahl.ComboBox1.Value, Operator:=xlAnd
        .AutoFilter field:=2, Criteria1:=">=" & CLng(Date), Operator:=xlAnd
        
    End With
    
    Range("Tabelle1").Sort Key1:=Range("D5"), Order1:=xlAscending, Header:=xlYes
    
End Sub

是否有可能首先应用“Gremium”过滤器与combobox 1(列1有委员会值),然后combobox 2显示该特定委员会值的所有可用日期值?

cyvaqqii

cyvaqqii1#

也许像这样的东西。。

Sub standardfilter()

    Dim resultsDictionary As Object
    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim rng As Range
    Dim rw As Range
    
    Me.ComboBox2.Clear
    
    Set ws = ActiveSheet
    Set tbl = ws.ListObjects("Tabelle1")
    
    With tbl
    
        'clear any pre-existing filters
        If .ShowAutoFilter Then
            With .AutoFilter
                If .FilterMode Then .ShowAllData
            End With
        End If
        
        With .Range
            .AutoFilter field:=1, Criteria1:=Me.ComboBox1.Value
            .AutoFilter field:=2, Criteria1:=">=" & Date
            .Sort Key1:=.Range("D5"), Order1:=xlAscending, Header:=xlYes
        End With
        
        On Error Resume Next
        Set rng = .DataBodyRange.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        
        If rng Is Nothing Then Exit Sub
        
    End With
    
    Set resultsDictionary = CreateObject("Scripting.Dictionary")
    
    For Each rw In rng.Rows
        resultsDictionary(rw.Cells(2).Value) = "" 'second column/Gremientermin
    Next rw
    
    Me.ComboBox2.List = resultsDictionary.keys()
    
End Sub

相关问题