Delete rows between two texts in ColumnA

nevsky092315

New Member
Joined
May 3, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to build a macro for the following condition:

Find the cell in column A that has Text A and delete all rows until that cell and then find Text B and delete all rows until the next Text A
and again find the next Text B and so on... this loop needs to repeat for minimum of 4 iterations to maximum of 12 iterations.

Sub FindTextAB()
Find_TextA
Find_TextB
End Sub
--------------------------------------------
Sub Find_TextA()
Do Until ActiveCell.Value = "TextA"
Selection.EntireRow.Delete --->This loop is where I am facing error, macro freezes and it doesn't come out of the loop once there is no data in below cells)
Loop
End Sub
----------------------------------------------
Sub Find_TextB()

Cells.Find(What:="TextB", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
End Sub
----------------------------------------------

Your help is greatly appreciated.

Thank you,
Nevsky
 
You are welcome. Sometimes it takes a little back and forth to get it done. Thanks for the feedback.
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,559
Messages
6,120,208
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top