VBA--INPUT Box for Date Range-->Filter

NEW_2VBA

Board Regular
Joined
Dec 15, 2015
Messages
103
Happy Friday!
I'm attempting to create VBA code that allows users to use an Input Box to enter dates for filtering. So far I'm able to add one input box for the Start Date but had trouble when I tried entering the other box for the End Date. The column would ideally filter by the dates entered. Additionally, I need to filter by other set criteria below (bottom two lines of code before End With) & I found the code below doesn't use all text options listed in the Arrays. I'm pretty sure it's because I'm leaving something out. I appreciate any help in advance. THANK YOU!! :biggrin:

Code I have so far:

Dim ap, dt As Date, dt1 As Date
With Worksheets("TestWorkbook").Range("A1")
ap = Application.InputBox("Start Date")
dt = CDate(ap)
.AutoFilter 5, ">=" & dt
.AutoFilter field:=6, Criteria1:=Array("CLIENT1", "CLIENT2", "CLIENT3")
.AutoFilter field:=7, Criteria1:=Array("MS", "VA")
End With
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,007
Try:
VBA Code:
Sub FilterDate()
    Application.ScreenUpdating = False
    Dim sDate As String, edate As String
    sDate = InputBox("Please enter a start date.")
    edate = InputBox("Please enter an end date.")
    With Sheets("TestWorkbook").Cells(1, 1).CurrentRegion
        .AutoFilter Field:=5, Criteria1:=">=" & CDate(sDate), Operator:=xlAnd, Criteria2:="<=" & CDate(edate)
        .AutoFilter Field:=6, Criteria1:=Array("CLIENT1", "CLIENT2", "CLIENT3"), Operator:=xlFilterValues
        .AutoFilter Field:=7, Criteria1:=Array("MS", "VA"), Operator:=xlFilterValues
    End With
    Application.ScreenUpdating = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,119,223
Messages
5,576,827
Members
412,748
Latest member
MikeyP14
Top