Delete row when a cell contains specific text

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
241
I've been scouring these boards looking at different solutions for how to delete a row when there is a particular string of text in a cell, but nothing I try seems to work. Rather than beat my head against my desk any longer, I am going to just reach out and plead for help...

I have been given a medium sized spreadsheet (it varies each day) that management wants cleaned up. Starting in row 4, I want to delete the entire row if I find a particular text string (it could be PART of the cell and might not be the entire text in the cell) in a column. Here's some examples:

Column B might include the text "PT CO" - need to delete the entire row
Column E includes "FROZEN" - delete row
Column H included "ROUTE" - same
And so on...


I'm hoping (and assuming) that once I get code that works for one of my text strings, I can modify it to work for multiple ones in sequence as needed for each column...

Thanks for any help!
~ZM~
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about
Code:
Sub zombiemaster()
   Dim Ary As Variant
   
   Ary = Array(2, "*pt co*", 5, "Frozen", 8, "Route")
   With Sheets("[COLOR=#ff0000]Data[/COLOR]")
      For i = 0 To UBound(Ary) Step 2
         If .AutoFilterMode Then .AutoFilterMode = False
         .Range("[COLOR=#ff0000]A3:Z3[/COLOR]").AutoFilter Ary(i), Ary(i + 1)
         .AutoFilter.Range.Offset(1).EntireColumn.Delete
      Next i
      .AutoFilterMode = False
   End With
End Sub
Change sheet name and header range to suit
 
Upvote 0
Thank you! I changed "EntireColumn" to "EntireRow" and it works perfectly - I was able to add other parameters as well, and it worked like a charm.

You ROCK!
~ZM~
:cool:
 
Upvote 0
You're welcome & thanks for the feedback.
Apologies for the typo on EntireColumn :oops:
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

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