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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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