Select and hide between two rows

  • Thread starter Thread starter SteveG
  • Start date Start date
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?
 
For this you need to write a macro. If you know VBA Coding
It can do all the things, the you require.
 
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)
 
Back
Top