QP School
Filter data in a worksheet - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48)
+--- Thread: Filter data in a worksheet (/showthread.php?tid=5256)



Filter data in a worksheet - Qomplainerz - 07-27-2023

Example:

Sub FilterData()
    Dim filterRange As Range

    'Set the range to be filtered (assuming data starts from A1)
    Set filterRange = Range("A1").CurrentRegion

    'Apply filter to column A for values greater than 5
    filterRange.AutoFilter Field:=1, Criteria1:=">5"
End Sub

Explanation:

The code defines a subroutine named FilterData.
It declares a variable filterRange, which represents the range to be filtered. 
In this example, the range is set to the data starting from cell A1 using the CurrentRegion property.
The filterRange.AutoFilter method is used to apply a filter to the range.
Field:=1 specifies that the filter should be applied to the first column of filterRange (column A).
Criteria1:=">5" sets the filtering criteria to show only values greater than 5.