VBA - Filter by Input Variable - not working

dragon-goddess1990

New Member
Joined
May 18, 2011
Messages
25
Hi

I have got some code that filters several columns. But I have got one which filters by user's input called Date1. (they input via input box)

Sub OneMonthBeforeCCDateBACKLOGFilter()
Dim Date1 As Date
Date1 = InputBox(Prompt:="What is todays date?", _
Title:="Enter Todays Date", Default:="")
Selection.AutoFilter Field:=15, Criteria1:="CONTRACTOR", Operator:=xlAnd
Selection.AutoFilter Field:=14, Criteria1:="<>CEASED TRADING", Operator:=xlAnd
Selection.AutoFilter Field:=21, Criteria1:="", Operator:=xlAnd
Selection.AutoFilter Field:=18, Criteria1:="<=" & CStr(Date1), Operator:=xlAnd
Selection.AutoFilter Field:=18, Criteria1:="<=" & CStr(Date1), Operator:=xlAnd

It all goes fine as it puts the input into the custom criteria but its as if it doesnt run it.

When I manually went into the custom criteria after running the macro it shows the criteria but I have to click OK and then it displays the data. (when this criteria isnt active no data shows)

Hope you can help.

Amy
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
As you are looking to convert the date to string you might need to format it first so something like this

format (cstr(date1),"DDMMYY")
 
Upvote 0

Forum statistics

Threads
1,224,563
Messages
6,179,527
Members
452,923
Latest member
JackiG

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