#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default vba filter

Hi,

I have a table in excel that looks like this:

Book1 Author1 Categ1
Book2 Author2 Categ2
Book3 Author3 Categ3
Book4 Author4 Categ4

I also have a list : Book1, Book2

I want to write a vba code that deletes the entire lines of those
items in my table that are not apperearing on my list. Can anyone help
me?

Thank you
Gabriel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default vba filter

Gabriel
I'll assume your list is on Sheet "Two" and your data is on sheet "One".
Sub DeleteRows()
Dim TheRange As Range
Dim c As Long
With Sheets("One")
Set TheRange = .Range("A1", .Range("A" & Rows.Count).End(xlUp))
For c = TheRange.Count To 1 Step -1
If Range("TheList").Find(What:=TheRange(c), _
LookAt:=xlWhole) Is Nothing Then _
TheRange(c).EntireRow.Delete
Next
End With
End Sub

HTH Otto
"Gabriel" wrote in message
om...
Hi,

I have a table in excel that looks like this:

Book1 Author1 Categ1
Book2 Author2 Categ2
Book3 Author3 Categ3
Book4 Author4 Categ4

I also have a list : Book1, Book2

I want to write a vba code that deletes the entire lines of those
items in my table that are not apperearing on my list. Can anyone help
me?

Thank you
Gabriel



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default vba filter

If you have headings for your lists:

BookName AuthorName CatName
Book1 Author1 Categ1
Book2 Author2 Categ2
Book3 Author3 Categ3
Book4 Author4 Categ4

And your criteria list uses the same heading:

BookName
Book1
book2

And you assign the name "database" to all of the main list, including
headers

And you assign the name "criteria" to the criteria list, including the
heading,

then you can use this macro:

Sub DataDelete()
ExecuteExcel4Macro "data.delete()"
End Sub


This uses an old Excel 4 technique that is no longer part of the Excel user
interface but is still supported beneath the surface.

--
Jim Rech
Excel MVP


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default vba filter


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!
  #5   Report Post  
Posted to microsoft.public.excel.programming
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!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter PivotTable dropdown items to match report filter Catherine D Excel Discussion (Misc queries) 1 August 16th 08 12:12 AM
Copy only visible cells after filter is applied/ sum after filter MAM Excel Worksheet Functions 0 April 9th 08 04:09 AM
Excel auto filter doesn't recoginize case - won't filter AA from A Mikey Excel Discussion (Misc queries) 1 September 29th 05 08:18 PM
"Criteria Range" in the "Data/Filter/Advanced Filter" to select Du TC Excel Worksheet Functions 1 May 12th 05 02:06 AM
How to set multiple filter values for a filter in the page fields Simon Lenn Excel Programming 1 December 29th 03 09:35 PM


All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"