Filtering based on date using VBA

ajocius1

Board Regular
Joined
Dec 21, 2007
Messages
111
Office Version
  1. 365
Platform
  1. Windows
Hi, I am using macro to filter list of data and would like to select all records with date less than today. I have used following VBA code to do that:
VBA Code:
    ActiveSheet.Range("$A$5:$R$1000").AutoFilter Field:=18, Criteria1:="<" & Date, Operator:=xlAnd

This is one of few filters I apply, therefore Operator is AND.

I get empty list after running macro, but I can see that filter is applied. I do manually go into filter, it correctly points to Date Filter Before and has todays date. Once I go into filter manually and then go out without doing any changes, suddenly filtering is applied correctly and see the list of data as requested.

Why is my macro failing to achieve required result?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
yeah

i was about to say, its not being recognised as a date.

i have used CLng(Date)

Dave
 
Upvote 0
Glad its working, please mark as resolved if complete
 
Upvote 0
gordsky

Not sure the original poster has seen or tried these yet.
Think you confused my comment as being from the OP

Dave
 
Upvote 0

Forum statistics

Threads
1,226,214
Messages
6,189,671
Members
453,562
Latest member
overmyhead1

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