Filtering with a macro using input box + dates

olly_w

Board Regular
Joined
Jul 2, 2003
Messages
189
Hi guys
I've got a spreadsheet which in column 3, contains date and time e.g. 12/12/200 08:36 . What i want to do is have a macro embedded into a button which prompts the user for 2 dates, start and finish. The macro will then autofilter the records in the spreadsheet to only those in between the pre-entered dates. But my code isn't working, any ideas?


Sub PrintOutByMonth()
Dim FirstDate As Date
Dim LastDate As Date

Application.ScreenUpdating = False

FirstDate = Application.InputBox("Please Enter the First Date in DD MM YYYY hh:ss format: ", "Enter First Date")

LastDate = Application.InputBox("Please Enter the Last Date in DD MM YYYY format: ", "Enter Last Date")

Selection.AutoFilter Field:=1, Criteria1:=">=" & FistDate, Operator:=xlAnd _
, Criteria2:="<=" & LastDate

End Sub


Any help greatly appreciated, thanks in advance
olly
 
olly_w said:
Ok, the dates in column c are taken from excel from other cells using the ()now function, and formatted in the cell as a described earlier.

I can't help you any further unless you answer my questions.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,224,899
Messages
6,181,627
Members
453,058
Latest member
rmd0725

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