VBA to Apply Auto Filter

VBA to apply a filter on the table. Will hide rows that don’t match the filter criteria.
Add <> in front of the FilterTerm to filter out that word.
Add * around FilterTerm to make wildcard search, filters if that word is contained within the cell.

Apply Auto Filter with 1 criteria

rws = ActiveSheet.UsedRange.Rows.Count
Set FilterRng = ActiveSheet.Range(“A1:Z” & rws)
FilterRng.AutoFilter Field:=1, Criteria1:=”FilterTerm”

Apply Auto Filter with multiple criteria

rws = ActiveSheet.UsedRange.Rows.Count
Set FilterRng = ActiveSheet.Range(“A1:Z” & rws)
FilterRng.AutoFilter Field:=1, Criteria1:=Array( _
“FilterTerm1”, “FilterTerm2”), Operator:=xlFilterValues

Apply Auto Filter with 1 criteria to show does not contain FilterTerm

rws = ActiveSheet.UsedRange.Rows.Count
Set FilterRng = ActiveSheet.Range(“A1:Z” & rws)
FilterRng.AutoFilter Field:=1, Criteria1:=”<>FilterTerm”

Interested in learning new skills?