Add 3rd criteria to VBA filter

ChrisMac1

New Member
Joined
Jul 15, 2024
Messages
42
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I have a long code that includes the following...

ActiveSheet.Range("$A$1:$AG$10000").AutoFilter Field:=15, Criteria1:= _
"=EXAMPLE1", Operator:=xlOr, Criteria2:= _
"=EXAMPLE2"

It's a code to add a filter to column O to show all the EXAMPLE1 and EXAMPLE2's in the column, that will then be deleted using the follow on code. I need to add a third option to delete, how would I add EXAMPLE3 to the above please? My guesses and tests so far haven't worked...

Many thanks,
Chris.
 
How about
VBA Code:
ActiveSheet.Range("$A$1:$AG$10000").AutoFilter 15, Array("Example1", "Example2", "Example3"), xlFilterValues
 
Upvote 0
Hi Fluff, nice to hear from you again!

The filter worked but then the delete code misfired...

If ((ActiveSheet.AutoFilter.Range.SpecialCells(xlCellTypeVisible).Count / ActiveSheet.AutoFilter.Range.Columns.Count) - 1) > 0 Then '// Checks if the autofilter found anything
With Range("A2:AG" & lastrow)
.EntireRow.Delete
 
Upvote 0
Try it like
VBA Code:
With ActiveSheet
   .Range("$A$1:$AG$10000").AutoFilter 15, Array("Example1", "Example2", "Example3"), xlFilterValues
   .AutoFilter.Range.Offset(1).EntireRow.Delete
End With
 
Upvote 0
Solution
Wonderful stuff, as always Fluff, thanks very much. I'll test the full process, but the interim individual test on one sheet and just this code worked just fine, thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

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