Filter criteria

G

Guest

I am trying to filter a list using two date criteria, so that the returned
results are the values in between.

I have found from Ron deBRuin's website the following code as part of a
macro to filter a spreadsheet using two criteria:

rng.Autofilter Field:=4, Criteria1:=">=" & DateSerial(1947, 2,
23),_Operator:=xlAnd, Criteria2:="<=" & DateSerial(1988, 5, 7) '

This is doing exactly what I want except I need the two criteria to be
values in two cells on the spreadsheet.

Would anyone know how the code should be so that the two date criteria are
hard typed into the code but rather are taken from two populated cells on the
spreadsheet that the macro is filtering (the two cells are not in the list
being filtered).

Thanks
Tony
 
B

Bob Phillips

rng.Autofilter Field:=4, Criteria1:=">=" & Range("A1").Text, _
Operator:=xlAnd, Criteria2:="<=" & Range("A2").Text

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
R

Roger Govier

Hi Tony

Try
rng.Autofilter Field:=4, Criteria1:=">=" & Range("A1").Value, _
Operator:=xlAnd, Criteria2:="<=" & Range("B1").Value

Change A1 and B1 to suit.

Regards

Roger Govier
 

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