Delete row when a cell contains specific text

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
205
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~
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
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
 

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
205
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:
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,960
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
Apologies for the typo on EntireColumn :oops:
 

Watch MrExcel Video

Forum statistics

Threads
1,122,576
Messages
5,596,992
Members
414,115
Latest member
SFUser

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