Macro Date Selection

ponrajnadar28

New Member
Joined
Nov 1, 2018
Messages
1
I wanted to make it to where anytime I first go to a Report worksheet (like “Sheet1”), it defaults to the 4 most recent weeks’ worth of date:

  • “To” defaults to date with most recent data.
  • “From” defaults to 4 weeks prior to most recent data (“To” date minus 21 days).

Afterwards, anyone can change the date ranges to any date they want from the drop-down (they might only want to see 1 week, or maybe 8 weeks, etc.). Only when the worksheet initially activates do I want it to default to most recent 4 weeks’ worth of data.


I think the best way to accomplish this would be to use the Worksheet_Activate in Module1. Before it does any window resizing (maybe immediately after Application.ScreenUpdating = False ) to change the “To” date in Cell J8 to the most recent date option before today’s date ( DATE() ), and then change “From” in Cell H8 to equal the Date in J8 – 21 days .

Then rest of “Worksheet_Activate()” can continue with resizing the windows. And after done, the user can manually change the From/To dates to anything they want
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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