07-27-2023, 09:46 AM
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.
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.