Hello Friends,
Some years back a gentleman here provided me the below code which works perfectly for filtering the rows with one or more criteria in a cell with comma separated values & not only this but also works with multiple entries like values in different cells
Can someone pls amend the code to work for Columns
Starting column would be Column D
Criteria would be added in cell B1:B3
Some years back a gentleman here provided me the below code which works perfectly for filtering the rows with one or more criteria in a cell with comma separated values & not only this but also works with multiple entries like values in different cells
Can someone pls amend the code to work for Columns
Starting column would be Column D
Criteria would be added in cell B1:B3
VBA Code:
rivate Const SRA As String = "A2:AO2" 'address where you type the search criteria
Private Const dS As Long = 2 'row where you type the search criteria
Private Const dc As Long = 1 'First column of data
Private Const dr As Long = 4 'First row of data (exclude header)
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, J As Long, n As Long
Dim m As Long, p As Long
Dim r As Range
Dim arr, z, x
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If Not Intersect(Target, Range(SRA)) Is Nothing Then
n = Range(SRA).Resize(100000).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Application.ScreenUpdating = False
Range("A" & dr & ":A" & n).EntireRow.Hidden = False
If WorksheetFunction.CountA(Range(SRA)) > 0 Then
Rows(dS).AutoFit
For Each r In Range(SRA)
J = r.Column
If Len(Cells(dS, J)) > 0 Then
arr = Split(Cells(dS, J), ", ")
For i = dr To n
z = Cells(i, J).Text
If z = "" Then Rows(i).EntireRow.Hidden = True
If Rows(i).RowHeight > 0 Then
m = 0
For Each x In arr
m = m + InStr(1, z, x, 1)
If m > 0 Then Exit For
Next
If m = 0 Then Rows(i).EntireRow.Hidden = True
End If
Next
End If
Next
Else
Rows(dS).RowHeight = 35
End If
End If
On Error Resume Next
p = Range("A" & dr & ":A" & n).SpecialCells(xlCellTypeVisible).Cells.Count
Application.StatusBar = "Found " & p & " rows"
On Error GoTo 0
ActiveWindow.ScrollRow = 1
Application.ScreenUpdating = False
Application.Calculation = xlCalculationAutomatic
End Sub