Thread: vba filter
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach[_6_] Otto Moehrbach[_6_] is offline
external usenet poster
 
Posts: 201
Default vba filter

Gabriel
Let me see if I have this straight. You have a table of Book 1. etc and
Author 1 etc, and Categ 1. We can ignore the categ column.
You also have a list of books and a list of authors. You want to delete
any row of the table if its Book or if its Author is not on the respective
list. In other words, if we find a match with just one list, Book or
Author, the row stays. Is that right?
The following macro does that. The conditions a
The book list is named "BookList"
The author list is named "AuthorList"
Both the "BookList" and the "AuthorList" are on the same sheet,
and that sheet is the active sheet.
Your Table is on the "Table" sheet with the Books in Column A and the
Authors in Column B.
HTH Otto
Sub DeleteRows()
Dim TheRange As Range 'The rng of Column A of the Table sheet
Dim c As Long
Dim TheLists As Range
With Sheets("Table")
Set TheRange = .Range("A1", .Range("A" & Rows.Count).End(xlUp))
Set TheLists = Union(Range("BookList"), Range("AuthorList"))
For c = TheRange.Count To 1 Step -1
If TheLists.Find(What:=TheRange(c), _
LookAt:=xlWhole) Is Nothing Then
If TheLists.Find(What:=TheRange(c).Offset(, 1), _
LookAt:=xlWhole) Is Nothing Then _
TheRange(c).EntireRow.Delete
End If
Next
End With
End Sub
"Gabriel Matache" wrote in message
...

How would the Sub DeleteRows() would change if I had two lists, for
instance Book1 or Author2. In other words, all lines in my table should
be deleted if they not contain either Author1 or Book2.

Thank you in advance
Gabriel


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!