Delete Rows with a Specific Set of Letters

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
946
Office Version
  1. 2016
Platform
  1. Windows
Hello All,
I have the following:
VBA Code:
With Sheets("B&M")
      With .Range("K2", .Range("K" & Rows.Count).End(xlUp))
         .AutoFilter 1, "=ZZ"
         .Offset(1).SpecialCells(xlVisible).EntireRow.Delete
      End With
      .AutoFilterMode = False
End With

This is not working...
What I am trying, is to find any entries, with ZZ in a text string, starting in cell K2, to the bottom, and delete all rows that have the letters ZZ in column K.

For example:
If cell K762 has: HK4-ZZ-OP-9_week, then the row of 762 would be deleted. and so on.
However, not all cells will have HK4-ZZ-OP-9_week. Every cell that has ZZ will have different text.
Also, ZZ may not always be all caps. sometimes, it may be lower case as well.
Thanks for the help
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
How about
VBA Code:
With Sheets("B&M")
   .Range("K2", .Range("K" & Rows.Count).End(xlUp)).AutoFilter 1, "*ZZ*"
   .AutoFilter.Range.Offset(1).EntireRow.Delete
   .AutoFilterMode = False
End With
 
Upvote 0
Here is another code snippet that does not use AutoFilter which should also work...
VBA Code:
  Sheets("B&M").Columns("K").Replace "*ZZ*", "#N/A", xlWhole, , False, , False, False
  On Error GoTo NoZZ
  Sheets("B&M").Columns("K").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
NoZZ:
 
Upvote 0
How about
VBA Code:
With Sheets("B&M")
   .Range("K2", .Range("K" & Rows.Count).End(xlUp)).AutoFilter 1, "*ZZ*"
   .AutoFilter.Range.Offset(1).EntireRow.Delete
   .AutoFilterMode = False
End With
OK...This is Working, Thank you
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,996
Messages
6,122,636
Members
449,092
Latest member
bsb1122

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