Using string array as criteria in VBA autofilter

后端 未结 2 1419
自闭症患者
自闭症患者 2020-12-07 01:19

I\'ve searched other posts and found similar issues but nothing that could help me specifically. I\'m trying to take an array of strings and use it as a filter criteria. It\

2条回答
  •  情书的邮戳
    2020-12-07 02:01

    The Excel documentation for AutoFilter provides some guidance. The Operator parameter takes a XlAutoFilterOperator that specifies how Criteria1 is interpreted. In your case, specifying a value of xlFilterValues will cause Criteria1 to be properly interpreted as an array of filter values.

    The following example demonstrates this:

    Dim arr As Variant
    arr = Array("Alpha", "Bravo", "Charlie")
    
    Sheet17.Range("E1").AutoFilter _
        Field:=5, _
        Criteria1:=arr, _
        Operator:=xlFilterValues
    

提交回复
热议问题