autofilter of range problem

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
189
Hi,

Wondering if anyone can help with this....

I'm trying to make my code set up two filters on my sheet - the first is a date on column 39 (based on pre defined date dat minus 28days) and the second is to filter for containing not blank cells.

Code:
With Sheets("OPS PLANNER")
            .AutoFilterMode = False
                With .Range("A9:AT5010")
                     .AutoFilter
                     .AutoFilter Field:=39, Criteria1:="<=" & dat - 28
                     
                     .AutoFilter Field:=45, Criteria1:="<>"
                     
                End With

Exit Sub

It seems to run ok but for some reason is coming up with nothing even when there are results.

Probably something obvious! but can anyone help?

Thanks
Tom
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Your second criteria translates to "doesn't equal". What are you trying to get it to do because "doesn't equal" doesn't equate.
 
Upvote 0
Your second criteria translates to "doesn't equal". What are you trying to get it to do because "doesn't equal" doesn't equate.
Criteria1:="<>"
equates to "is not equal to blank", which is what the OP stated they want. If you record a macro to auto filter (Text Filter... -> Does not equal -> leave the top right box empty -> OK) the criteria is recorded as above.

Tom
If you change this line in your code does it help?
Rich (BB code):
.AutoFilter Field:=39, Criteria1:="<=" & CLng(dat - 28)
 
Upvote 0
Morning, yep - that seemed to be what the problem was.

I have changed it to be 28 days older than today and it seems to work

Code:
dat = ">=" &  date - 28

With Sheets("OPS PLANNER")
            .AutoFilterMode = False
                With .Range("A9:AT5010")
                     .AutoFilter
                     .AutoFilter Field:=39, Criteria1:=dat
                     
                     .AutoFilter Field:=45, Criteria1:="<>"
                     
                End With

Thanks
Tom
 
Upvote 0
Peter, just seen your reply - and thanks for your help.

I think I've kind of done a similar thing to you suggest?


Thanks
Tom
 
Upvote 0
Peter, just seen your reply - and thanks for your help.

I think I've kind of done a similar thing to you suggest?


Thanks
Tom
Your change doesn't work for me as I understand what you are trying to do, but if it is working for you, that's all that matters. :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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