【问题标题】:Advanced filter with multiple criteria具有多个条件的高级过滤器
【发布时间】:2017-11-14 10:48:18
【问题描述】:

有谁知道如何在下面的代码中应用高级过滤器后,我可以在 col E 中应用另一个过滤器来显示过滤数据的唯一值(无需摆脱已经过滤的内容?) - 任何帮助都会很大赞赏

Sub difficultQ()

    Dim x
    Dim Y

    x = "Match"

    Y = "Match1"

    Range("A1").Value = x

    Range("A2").Value = Y

    Range("M4").Select

    Range(Selection, Selection.End(xlDown)).Select

    Selection.AdvancedFilter Action:=xlFilterInPlace, criteriarange:=Range("A1:A2")

    ' In here I would like to have code that filtered col E
    ' on unique values, without getting rid of the advanced filter above

End Sub

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    您不能应用两个高级过滤器。您需要修改过滤条件并使用如下公式:

    Sub difficultQ()
    
        Dim x
        Dim Y
        Dim lastRow As Long
    
        Y = "Match1"
    
        Range("A1").Value = vbNullString
    
        Range("A2").Formula = "=AND(M5=""" & Y & """,COUNTIFS($E$5:$E5,E5,M$5:M5,""" & Y & """)=1)"
        lastRow = Cells(Rows.Count, "M").End(xlUp).Row
        Range("E4:M" & lastRow).AdvancedFilter Action:=xlFilterInPlace, criteriarange:=Range("A1:A2")
    
    End Sub
    

    【讨论】:

    • 非常感谢罗里!这样就完美解决了问题。
    猜你喜欢
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 2021-08-15
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多