Macro runtime error 1004 with Autofilter

L

Lorna B

I have a macro that invokes Autofilter, however, when I try to run it, after
receiving input from the user, it fails at the Autofilter command. The
message is Autofilter method of range class failed. Can someone help me with
this? This is the entire macro from the start where it selects a range and
clears it, then selects the range for the filter.

Range("A3").Select
Selection.CurrentRegion.Select
Selection.Clear
Sheets("Satisfaction input sheet").Select
Range("A4").Select
Selection.CurrentRegion.Select
Selection.Copy
Sheets("query").Select
Range("A3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
c1 = InputBox("Enter Date From")
c2 = InputBox("Enter Date To")
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=">=" & c1 & ",",
Criteria2:="<=" & c2
Range("A3").Select
 
D

Don Guillett

Lorna, See my answer in your original post. Your macro below does not make a
selection to filter. Try this.


Range("A3").CurrentRegion.Clear

Sheets("Satisfaction input sheet").Select
Range("A4").CurrentRegion.Copy Sheets("query").Range("A3")


c1 = InputBox("Enter Date From")
c2 = InputBox("Enter Date To")
With sheets("query").Range("A3:D7")' adjust to suit
.AutoFilter
.AutoFilter Field:=1, Criteria1:=">=" & c1 & "" _
, Operator:=xlAnd, Criteria2:="<=" & c2 & ""
End With
End Sub
 
L

Lorna B

Thank you for your continued help Don. It must be so satisfying to be such a
clever guy! A great big hug to you. Lorna
 
Top