Macro for Date Filter

jchakkalakal

New Member
Joined
Nov 4, 2010
Messages
24
Spreadsheet that is used for delivery schedule. Column A is a list of locations, Column B is a list of date, both past due and for the upcoming 12 months.

Macro Needed:- On any given day one would open the spreadsheet and hit a macro button that can filter column B to show delivery dates that are past due and delivery dates that are 3 weeks out, based on todays date according to time/date of Windows OS.

I know you can just do a manual filter, but for some reason it proves to be challenge for some of our older salespeople.
Thank you for your help.
<!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi

The code below will filter column B for dates older than Today and 3weeks from Today into the future. Hope it helps.

Sub d_filter()

Dim dt As Date

dt = Date 'today

x = dt + 21 ' plus 3wks
d = Day(x)
M = Month(x)
y = Year(x)

Z = M & "/" & d & "/" & y

C = "<=" & Z

ActiveSheet.Range("a1").AutoFilter _
field:=2, _
Criteria1:=C

End Sub
 
Upvote 0

Forum statistics

Threads
1,222,246
Messages
6,164,805
Members
451,917
Latest member
WEB78

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