Macro runtime error 1004 with Autofilter

G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top