Excel VBA 多重筛选

Excel VBA 多重筛选

Sub FilterOnValues()
'PURPOSE: Filter on specific values


Dim rng As Range

Set rng = ActiveSheet.Range("B7:D18")
FilterField = WorksheetFunction.Match("Country", rng.Rows(1), 0)

'Turn on filter if not already turned on
  If ActiveSheet.AutoFilterMode = False Then rng.AutoFilter
      
'Filter Specific Countries
  rng.AutoFilter Field:=FilterField, Criteria1:=Array( _
    "Russia", "China", "Greece", "France"), Operator:=xlFilterValues
      
End Sub

Sub FilterOutValues()
'PURPOSE: Filter out specific values (need to use Advanced Filtering)

Dim rng As Range

'Set variable equal to data set range
  Set rng = Me.Range("B7:D18")

'Filter out certain values (filter indicators will not appear!)
  rng.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
    Me.Range("G2:J3"), Unique:=False

End Sub

Excel VBA 多重筛选_第1张图片

https://www.thespreadsheetguru.com/example-files

有很多有用的技巧参考

你可能感兴趣的:(Excel VBA 多重筛选)