del certain rows based on word search

R

Robert

Hello,
I import about 50 pages of data from another program that leaves page
headers which consist of 10 rows of junk. In between these rows of headers,
there is aprox. 10 to 12 rows of good data, not always the same number of
rows. I would like to end up with just the data and delete the junk rows. The
one common identifier (for search purposes) I see is the company name in
column E of the top of the header (the 1st row of junk). How would I go about
automatically searching out and deleting the row that includes the company
name, as well as the 9 tows beneath it?. This header exists about 50 times,
so I need something that can search through and delete all of the headers.

thanks in advance for any help,
Robert
 
G

Gord Dibben

Sub DeleteRows()
FindString = "company name" 'adjust to company name
Set b = Range("E:E").Find(what:=FindString, lookat:=xlWhole)
While Not (b Is Nothing)
b.Resize(10).EntireRow.delete
Set b = Range("E:E").Find(what:=FindString, lookat:=xlWhole)
Wend
End Sub


Gord Dibben MS Excel MVP
 
R

Robert

Sweet! This works great. Thanks Gord!
Robert

Gord Dibben said:
Sub DeleteRows()
FindString = "company name" 'adjust to company name
Set b = Range("E:E").Find(what:=FindString, lookat:=xlWhole)
While Not (b Is Nothing)
b.Resize(10).EntireRow.delete
Set b = Range("E:E").Find(what:=FindString, lookat:=xlWhole)
Wend
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top