Macro using autofilter

G

Guest

I am building a macro so that people in my organization can produce reports
based on a customer satisfaction spreadsheet database. I need to be able to
pull data from the customer responses based on date ranges and I am thinking
that the autofilter is the best choice for this. I want people to be able to
input a from date for the greater than = to choice in autofilter and input
and end date for the less than = to choice. I would then like to have them
click on a radio button to initiate the macro and have the macro run the
routine to pull the information to a query spreadsheet from the satisfaction
spreadsheet based on the dates given. Piece of cake I am sure for you MVP
types, but I am stumped on how to have the autofilter pull the dates for the
query from the input cells. :(

Your help would be hugely appreciated.
 
D

Don Guillett

As always, post your coding efforts for comments and suggestions.
c1 = InputBox("Enter Criteria 1")
MsgBox c1
 
G

Guest

Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=">=subroutine",
Operator:=xlAnd _
, Criteria2:="<=subroutine2"

Sorry Don, I have never done this before. (see sheepish expression on my
face). It is in the part for criteria 1 and criteria 2 that I need the macro
to pause for input, or else to reference another cell in the first or second
row of the spreadsheet to get the date from and date to. Thanks for your
help!
 
D

Don Guillett

try this. I didn't test. BTW, you should try to NOT use selections. Use the
range instead. I suspect that the rest of your code is also full of
unnecessary and undesirable selections.

c1 = InputBox("Enter Criteria 1")
c2= InputBox("Enter Criteria 2")
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=">=" & c1 &",
Operator:=xlAnd _
, Criteria2:="<=" & c2
 
G

Guest

I must be a real idiot. Thank you so much for being so helpful. I have
changed my code, however when I test the macro I get a runtime error at the
"Selection.AutoFilter"
 
D

Don Guillett

I had "" wrong. NOW tested. Use the top of your range
Sub FilterInputCriteria()

c1 = InputBox("Enter Criteria 1")
c2 = InputBox("Enter Criteria 2")

With Range("A7:D7")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=">=" & c1 & "" _
, Operator:=xlAnd, Criteria2:="<=" & c2 & ""
End With
End Sub
 

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

Similar Threads


Top