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
 

igold

Well-known Member
Joined
Jul 8, 2014
Messages
2,523
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
You are welcome. Sometimes it takes a little back and forth to get it done. Thanks for the feedback.
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Watch MrExcel Video

Forum statistics

Threads
1,126,957
Messages
5,621,823
Members
415,859
Latest member
Vain

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
Top