Macro Autofilter by today date?

meetz

New Member
Joined
Dec 29, 2015
Messages
7
How to use today formula in below coding to get all the records before today's date?

Code:
[COLOR=#333333]ActiveSheet.Range("$A$2:$M$377").AutoFilter Field:=7, Criteria1:=[/COLOR]"50"[COLOR=#333333]
[/COLOR][COLOR=#333333]        "<29.1.2011", Operator:=xlAnd[/COLOR]
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,

This piece of code shows all dates before today.

Code:
ActiveSheet.Range([COLOR=#333333]("$A$2:$M$377").A[/COLOR]utoFilter Field:=7, Criteria1:= "<" & Format(Now(), "mm/dd/yyyy")
 
Upvote 0
Thank you for the answer.

My question is if i want for today's date and every day i have to work on. So on daily bases i don't want to change date in coding.

Hi,

This piece of code shows all dates before today.

Code:
ActiveSheet.Range([COLOR=#333333]("$A$2:$M$377").A[/COLOR]utoFilter Field:=7, Criteria1:= "<" & Format(Now(), "mm/dd/yyyy")
 
Upvote 0
The "Now()" part returns the date of the day you run the code on. So tomorrow it will filter before tomorrow.
It seems that this is the way you want it to work?
 
Upvote 0
The "Now()" part returns the date of the day you run the code on. So tomorrow it will filter before tomorrow.
Note that Now() actually returns date AND time (you are dropping the time part with the Format function).
If you want just the date portion, you could just use Date().
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
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