sachavez

Active Member
Joined
May 22, 2009
Messages
469
Hello!

I'm looking to delete all rows not containing the following in column E. I have the following code, but it's not working. Any ideas?

Code:
With ActiveSheet.UsedRange
       .AutoFilter field:=5, Criteria1:=Array("<>PN", "<>RN", "<>DR", "<>TA"), Operator:=xlFilterValues
       .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You could also try AutoFilter with the criteria built up this way.

Code:
Sub AutoFltrMultiNotEqual()
  Dim sCrit As String
  Dim a As Variant, itm As Variant
  
  With ActiveSheet.UsedRange
    a = .Columns(5).Value
    For Each itm In a
      Select Case itm
        Case "PN", "RN", "DR", "TA"
        Case Else: sCrit = sCrit & "|" & itm
      End Select
    Next itm
    .AutoFilter Field:=5, Criteria1:=Split(Mid(sCrit, 2), "|"), Operator:=xlFilterValues
    .Offset(1).EntireRow.Delete
    .AutoFilter
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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