Multiple Filtering in Excel VBA?

后端 未结 2 520
生来不讨喜
生来不讨喜 2021-01-13 00:20

I\'m trying to filter my data using 2 columns and 2 different filter requirements.

    ActiveSheet.AutoFilterMode = False
    ActiveSheet.Range(\"$K$2:$ZZ$20         


        
相关标签:
2条回答
  • 2021-01-13 00:59

    Almost. Managed to do this using an array. The Range does not need to be the same by the way.

         ActiveSheet.AutoFilterMode = False
        ActiveSheet.Range("$E$2:$ZZ$200").AutoFilter Field:=nice, Criteria1:="yes"
        ActiveSheet.Range("$E$2:$ZZ$200").AutoFilter Field:=1, Criteria1:=Array( _
        "Filter 1", ""Filter 2", "On "Filter 3", ""Filter 4", ""Filter 5"), Operator:=xlFilterValues
    
    0 讨论(0)
  • 2021-01-13 01:10

    You have to use the same Range("$K$2:$ZZ$200") for both AutoFilter statements:

    ' Column A = Field 1
    ActiveSheet.Range("$K$2:$ZZ$200").AutoFilter Field:=1, Criteria1:="yes"
    ' Column E = Field 5
    ActiveSheet.Range("$K$2:$ZZ$200").AutoFilter Field:=5, Criteria1:="Low"
    

    Also, you may need to set ActiveSheet.AutoFilterMode = True, but I'm not entirely sure.

    0 讨论(0)
提交回复
热议问题