How to add a Message box in a Macro which uses Auto-filter in Excel

Hi Guys, I wish to amend this macro so it selects an Autofilter in an Excel spreadsheet and then selects
a date in a column defined by what I input into a message box. How do I do this? In the code below, I have recorded a Macro which filters in Column G for the rows prior to 07/09/2015, but I wish to input a different date every week into a Message box so it does the same. I enclose the spreadsheet with Macro.

    ActiveSheet.Range("$A$1:$AF$8461").AutoFilter Field:=7, Criteria1:= _
        "<07/09/2015", Operator:=xlAnd
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try
Sub Macro1()
' Macro1 Macro

    Sheets("All trades").Select
    ActiveSheet.Range("$A$1:$AF$80000").AutoFilter Field:=4, Criteria1:=Array( _
        "IRS", "Loan", "SCF", "SCF Adjustment"), Operator:=xlFilterValues
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp
    strDate = Application.InputBox("Enter A Date")
    If IsDate(strDate) Then
        ActiveSheet.Range("$A$1:$AF$8461").AutoFilter Field:=7, Criteria1:= _
        "<" & strDate, Operator:=xlAnd
        MsgBox "Invalid date"
    End If
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
[ fanpages ]IT Services ConsultantCommented:

Do you simply wish to enter a date into an Input Box, use the value in cell [C9] of the [Macros] worksheet, or automatically use a date based on whatever day (of the month/year) the button is clicked?

PS. I would also suggest using a format like [Dd-Mmm-YYYY] (i.e. 07-Sep-2015) to avoid confusion with the transposition of the day/month values; 09-Jul-2015, for example.
JCutcliffeAuthor Commented:
Hi, I am trying to use this code to delete trades in between 07th Sep 2015 and 14th Sep 2015 using the Message box  but its not working any ideas?

    Sheets("All trades").Select
    strdate = Application.InputBox("please delete all trades between which dates?")

    ActiveSheet.Range("$A$1:$AF$111584").AutoFilter Field:=6, Criteria1:= _
        ">=" & strdate, Operator:=xlAnd
          strdate1 = Application.InputBox("please delete all trades between which dates?")
    ActiveSheet.Range("$A$1:$AF$111584").AutoFilter Field:=7, Criteria1:= _
        "<=" & strdate1, Operator:=xlAnd
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.