Macro to set a range date

neo_cd

New Member
Joined
Apr 17, 2018
Messages
2
Hello,

I have a spreadsheet with 143 rows containing a "Target Date" column.

I would like to create a macro that will be able to set a range and filter the dates. As an example, I would like to filter the rows containing a date from May 31, 2018 to July 31, 2018.

What would be the best option to achieve that? To have an input message box and type the dates or put the requested dates in 2 differents cells and mention them in the macro?

Let me know if my request is not clear enough and I will provide more details.

Thanks!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to MrExcel,

That's largely a matter of personal preference. I personally would rather use an interface that has the two cells (Start date, end date), and a button that says something like "Update Filter".
 
Upvote 0
Thanks Jerry!

Finally I found the following solution which is perfect for my needs :) :

Dim W1Startdate As Date, W1Enddate As Date

Selection.NumberFormat = "mm/dd/yyyy"

W1Startdate = ActiveSheet.Range("G1")
W1Enddate = ActiveSheet.Range("I1")

ActiveSheet.Range("A4:AH143").AutoFilter Field:=9, Criteria1:=">=" & W1Startdate, Criteria2:="<=" & W1Enddate
ActiveSheet.Range("A4:AH143").AutoFilter Field:=9, Criteria1:=">=" & W1Startdate, Criteria2:="<=" & W1Enddate
 
Upvote 0

Forum statistics

Threads
1,214,840
Messages
6,121,895
Members
449,058
Latest member
Guy Boot

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