Excel VBA Autofilter

Use the VBA AutoFilter feature to find, show, or hide values—in one or more columns of data. You can filter based on choices you make from a list, or search to find the data that you seek. When you filter data, entire rows will be hidden if the values in one or more columns don\’t meet the filtering criteria.

\' How to Apply autofilter

Sub Apply_autofilter()
Worksheets(\"Sheet1\").Range(\"A1\").AutoFilter
End Sub

\'How to remove filter from a particular sheet

Sub Remove_autofilter()
Worksheets(\"Sheet1\").AutoFilterMode = False
End Sub

\' Command to on and off autofilter
Sub Apply_autofilter_ON_OFF()
If Not Worksheets(\"Sheet1\").Range(\"A1\").AutoFilter Then
Worksheets(\"Sheet1\").Range(\"A1\").AutoFilter
End If
End Sub



Sub Remove_autofilter()
Worksheets(\"Auto filter Criteria\").AutoFilterMode = False
End Sub


Sub filter_Criteria_Name()
Worksheets(\"Auto filter Criteria\").Range(\"A1:E17\").AutoFilter Field:=1, Criteria1:=\"Sachin\"
End Sub


Sub filter_Criteria_City()
Range(\"A1:E17\").AutoFilter Field:=2, Criteria1:=\"Mumbai\"
End Sub

Sub filter_Criteria_Sales()
Range(\"A1:E17\").AutoFilter Field:=3, Criteria1:=\">60\"
End Sub


Sub Remove_autofilter()
Worksheets(\"and_or\").AutoFilterMode = False
End Sub

Sub two_condition_autofilter()
Range(\"A1:E17\").AutoFilter Field:=3, Criteria1:=\">30\", Operator:=xlAnd, Criteria2:=\"<50\"
End Sub


Sub two_condition_autofilter_City()
Range(\"A1:E17\").AutoFilter Field:=2, Criteria1:=\"pune\", Operator:=xlOr, Criteria2:=\"Mumbai\"
End Sub

Sub Remove_autofilter()
Worksheets(\"And two columns\").AutoFilterMode = False
End Sub

Sub autoflilter_and()
With Range(\"A1:E17\")
.AutoFilter Field:=1, Criteria1:=\"Sachin\"
.AutoFilter Field:=2, Criteria1:=\"Mumbai\"
End With
End Sub


Sub autoflilter_and_2()
With Range(\"A1:E17\")
.AutoFilter Field:=1, Criteria1:=\"Sachin\"
.AutoFilter Field:=2, Criteria1:=\"pune\", Operator:=xlOr, Criteria2:=\"Mumbai\"
\'.AutoFilter Field:=3, Criteria1:=\">50\"
End With
End Sub


Sub autoflilter_and_3()
With Range(\"A1:E17\")
.AutoFilter Field:=1, Criteria1:=\"Sachin\"
.AutoFilter Field:=2, Criteria1:=\"Mumbai\"
.AutoFilter Field:=3, Criteria1:=\">50\"
End With
End Sub

Sub Remove_autofilter()
Worksheets(\"Top_Bottom N\").AutoFilterMode = False
End Sub


Sub top_Nqty()
ActiveSheet.Range(\"A1\").AutoFilter Field:=3, Criteria1:=\"5\", Operator:=xlTop10Items
End Sub


Sub Bottom_Nqty()
ActiveSheet.Range(\"A1\").AutoFilter Field:=3, Criteria1:=\"5\", Operator:=xlBottom10Items
End Sub