The below code is used to set Autofiler
data on the active sheet.
It works , But If I later used autofiletr on any column then all the hidden rows are shown again.
My aim is to use a helper column and set filter on value.
In advance, thanks for any help.
Option Explicit
Option Compare Text
Sub AutoFilter_on_visible_data()
Dim ws As Worksheet, arr, i As Long, lastR As Long, HdRng As Range, rng As Range
Set ws = ThisWorkbook.ActiveSheet
lastR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
arr = ws.Range("A3:R" & lastR).Value2 'Place the relevant columns in an array for faster iteration
For i = 1 To UBound(arr)
If ws.Rows(i + 2).Hidden = False Then '(i + 2) because Data starts at Row_3
If Not arr(i, 2) Like "*Oil*" And _
Not arr(i, 5) Like "*-SYS-14" And _
Not arr(i, 6) Like "*Oil" Then
addToRange HdRng, ws.Range("A" & i + 2) 'Make a union range of the rows NOT matching criteria...
End If
End If
Next i
Application.ScreenUpdating = False
If Not HdRng Is Nothing Then HdRng.EntireRow.Hidden = True 'Hide not matching criteria rows.
Application.ScreenUpdating = True
End Sub
Private Sub addToRange(rngU As Range, rng As Range)
If rngU Is Nothing Then
Set rngU = rng
Else
Set rngU = Union(rngU, rng)
End If
End Sub