Autofilter for Todays date using VBA

dixon1983

Board Regular
Joined
Apr 23, 2005
Messages
175
Hi,
I have a macro that I want to autofilter a sheet of data with the criteria being Todays date.

What criteria should I put in the line of code below and what format should the data in the column be in?

Selection.AutoFilter Field:=11, Criteria1:= ???

I have tried putting TODAY and NOW in there but it doesnt work.

Thanks for any help
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Is there a way you could get it to return the Max value in the column for the filter? This would do also.
 
Upvote 0
If your recorded macro works I don't understand why:

Selection.AutoFilter Field:=11, Criteria1:=Format(Date, Selection.Cells(2, 11).NumberFormat)

doesn't work.

How about?

Selection.AutoFilter Field:=11, Criteria1:=Format(Date, "dd/mm/yyyy")

Selection.AutoFilter Field:=11, Criteria1:=Format(Date, "Short Date")

Selection.AutoFilter Field:=11, Criteria1:=Format(WorksheetFunction.Max(Selection.Columns(11)), "dd/mm/yyyy")
 
Upvote 0
Hi andrew,
I'm just leaving work now. I will try the suggested codes tomorrow when I get in and let you know if any of them work.

Thanks a lot for all of your help on this matter.
 
Upvote 0
Andrew,
Just got the bottom one of the 3 working. Works a treat now.

Thanks a lot for all your help, much appreciated.

:)
 
Upvote 0
Try one of these:

Selection.AutoFilter Field:=11, Criteria1:=CLng(Date)

Selection.AutoFilter Field:=11, Criteria1:=">" & CLng(Date) - 1, Operator:=xlAnd, Criteria2:="<" & CLng(Date) + 1

The second one is perfect.. Thankssssssssssssssssssssssssssssssssssssssssssssss Mr. Andrew Poulsom

Thank you a lot.. you've save me a lot of tiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiime
 
Upvote 0
Hi , I need some help for above code , I am trying to get last 5 business days from today by filtering but I am unable to getting that , I tried by changing code in different ways
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,861
Members
449,052
Latest member
Fuddy_Duddy

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