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

NEW_2VBA

Board Regular
Joined
Dec 15, 2015
Messages
106
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

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