VBA to filter on a column with Dates

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

Can anyone please spot my error on this code

I am trying to filter on dates Greater than Today()

It is applying the filter on the correct column but it's not applying the value, net result everything is filtered out

Code:
Dim Myval as Date
MyVal = Date
FilterRange.AutoFilter field:=24, Criteria2:=">" & MyVal
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Why Criteria2 and not Criteria1? also try
Code:
Dim Myval as Long
MyVal = CLng(Date)

Also are the dates in the cells real dates or text?
 
Last edited:
Upvote 0
Try
Code:
FilterRange.AutoFilter Field:=24, Criteria1:=">" & CLng(Myval)
 
Upvote 0
Thank you both for your reply

Is it possible to add another filter on a different column at the same time

Something like this

Code:
 FilterRange.AutoFilter field:=21, Criteria1:="*Out*"
                FilterRange.AutoFilter field:=24, Criteria2:="<" & CLng(MyVal)
 
Upvote 0
Not like that, you write it as 2 separate lines.

Code:
FilterRange.AutoFilter field:=21, Criteria1:="*Out*"
FilterRange.AutoFilter field:=24, Criteria1:="<" & CLng(MyVal)
 
Upvote 0
Mark can I bother you again please on the second filter is it possible to say show all blanks in field 24 and "<" & CLng(MyVal)

Code:
 [LEFT][COLOR=#333333][FONT=monospace]FilterRange.AutoFilter field:=21, Criteria1:="*Out*"
        FilterRange.AutoFilter field:=24, Criteria1:="<" & CLng(MyVal)[/FONT][/COLOR][/LEFT]
 
Upvote 0
Code:
FilterRange.AutoFilter field:=24, Criteria1:="<" & CLng(MyVal), Operator:=xlOr, Criteria2:="="
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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