Thread: Advanced Filter
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.misc,microsoft.public.excel
merjet merjet is offline
external usenet poster
 
Posts: 812
Default Advanced Filter

That's a little more specific. Alright, suppose A1:E10 is filled with
random numbers between 1 and 100, and you want to display a row only
if it contains one of the numbers in A13:D13. Then the folowing will
do that.

Sub MyFilter()
Dim rngCrit As Range
Dim c As Range
Dim bFound As Boolean
Dim iRow As Integer
Dim iCol As Integer
Dim ws As Worksheet

UndoMyFilter
Set ws = Sheets("Sheet1")
Set rngCrit = ws.Range("A13:D13")
For iRow = 1 To 10
bFound = False
For iCol = 1 To 5
For Each c In rngCrit
If ws.Cells(iRow, iCol) = c Then
bFound = True
Exit For
End If
Next c
Next iCol
If bFound = False Then ws.Rows(iRow).Hidden = True
Next iRow
End Sub

Sub UndoMyFilter()
Sheets("Sheet1").Rows("1:10").Hidden = False
End Sub

Hth,
Merjet