[RESOLVED] Filtered Date selection?
Guys,
Can you help me, I have written some code to filter some data by date.
Code:
' Sets the Date criteria for searching
TDate = Format((Now - 2), "dd/mm/yyyy")
' Filters for all receipts that are older than 24 hours
Selection.AutoFilter Field:=7, Criteria1:="<=" & TDate
All data is in the correct format, and when the code is run the filter is activated with the relevant search criteria but nothing is displayed in the data file.
However when I go into the filter manually on the data file, all the coded criteria is correct and when I confirm manually the filtered data is displayed.
Why is the code not automatically displaying the data?
Thanks
SJ
Re: Filtered Date selection?
Try this:
Code:
Selection.AutoFilter Field:=7, Criteria1:="<=" & CDbl(Now - 1)
That is filter for record older than 24 hours from current date-time (Now).
If the filtered column contains only dates (no time portion) and you want to filter for records that is on any day before yesterday then use this:
Code:
Selection.AutoFilter Field:=7, Criteria1:="<=" & CDbl(Date - 2)
or
Code:
Selection.AutoFilter Field:=7, Criteria1:="<" & CDbl(Date - 1)
Ps. If you need the date with time portion then use Now() function, if just need the date without time then use Date() function.
Now = Date + Time
Re: Filtered Date selection?
Anhn,
Thanks it worked a treat.