Trouble with Advanced Filter

RunTime91

Active Member
Joined
Aug 30, 2012
Messages
290
Office Version
  1. 365
Hello ~

Haven't experienced this before...

Below is basic Advanced Filter code using 2 criteria: "does not equal Lunch" and "does not equal Holiday"

When I run this code it won't filter for either of the two criteria

Code:
With Sheets("Sheet1")
    .Range("P2") = "<>" & "Lunch"
     .Range("P3") = "<>" & "Holiday"
    .Range("A1:J4705").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.Range _
        ("M1:V3"), CopyToRange:=.Range("Y1:AC1"), Unique:=False
End With

However, if I change the CriteriaRange to the below code it will filter for: "Does not equal Lunch"
Code:
With Sheets("Sheet1")
    .Range("P2") = "<>" & "Lunch"
     '.Range("P3") = "<>" & "Holiday"
    .Range("A1:J4705").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.Range _
        ("M1:V2"), CopyToRange:=.Range("Y1:AC1"), Unique:=False
End With

Likewise it I move "<>" & "Holiday" to .Range("P2") in the above code it will work. Thus I know there is nothing crazy with the criteria values or formatting causing the no filter in the first code.


Finally, if I add another header title for the column I'm filtering (as if I were filtering on a date range) and run the code below it will also work.
Code:
With Sheets("Sheet1")
    .Range("P2") = "<>" & "Lunch"
    .Range("Q2") = "<>" & "Holiday"
    .Range("A1:J4705").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.Range _
        ("M1:W2"), CopyToRange:=.Range("Z1:AD1"), Unique:=False
    End With

So for whatever reason when I stack the criteria in P2 & P3 and use the CriteriaRange of ("M1:V3") it won't work at all.

Help?
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Still can't get this to work and I have no idea what I'm doing wrong here... Can anyone see anything that might be causing the first window of code to not work?

Thanks...
 
Upvote 0
Through continued research I learned that apparently you cannot use the "<>" operator in an "OR" Criteria format with advanced filter.
Thus, the reason the code in the 3rd window above works is because it is written in a an "AND" Criteria format.
I think we can label this one solved...

On to the next mystery...
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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