Select and hide between two rows

S

SteveG

I have a long text file from which I want to extract blocks of data.

As a text import all the text starts in Column A. There are about
1000 lines in each file.

I want to:

1) Search for a word "apple" within each string/row then
2) Search for another word "bacon" in another string/row then ...
3) Select and hide the rows from row "apple" to row "bacon"
4) Repeat for the next occurance "apple" to "bacon". There are 29
occurances in each file.

Once I am sure that I have the correct selection I would then delete
the hidden rows.

Any ideas?
 
R

rshewade

For this you need to write a macro. If you know VBA Coding
It can do all the things, the you require.
 
B

Bob Phillips

Sub Clearout()
Dim LastRow As Long
Dim mpCell As Range
Dim mpStart As Long
Dim mpEnd As Long

LastRow = Range("A" & Rows.Count).End(xlUp).Row
Do
Set mpCell = Nothing
Set mpCell = Columns(1).Find("apple", LookIn:=xlValues)
If Not mpCell Is Nothing Then
mpStart = mpCell.Row
Set mpCell = Nothing
Set mpCell = Columns(1).Find("bacon", LookIn:=xlValues)
If Not mpCell Is Nothing Then
mpEnd = mpCell.Row
Rows(mpStart & ":" & mpEnd).Delete
End If
End If
Loop Until mpCell Is Nothing
End Sub





--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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