Delete Rows with a Specific Set of Letters

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
955
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,215,497
Messages
6,125,160
Members
449,209
Latest member
BakerSteve

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