Cell references in macros

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a macro with the following statement:


Selection.AutoFilter Field:=1, Criteria1:=">=5/15/2006", Operator:=xlAnd _
, Criteria2:="<=5/28/2006"

I want to replace the two dates with references to the values in cells B1
and B2 in the sheet "Macro Data". How do I do this?

Dan
 
Dan, you can play with this: (values in A1 & A2)

Selection.AutoFilter Field:=1, Criteria1:=">=" & Cells(1, 1),
Operator:=xlAnd _
, Criteria2:="<=" & Cells(2, 1)

jr
 
JR,

Thank you for your reply.

I have a date in both B1 and B2 (sheet "Macro Data"). In my macro, I have
the following code:

Dim EndDate As Date
Dim StartDate As Date

StartDate = Sheets("Macro Data").Cells("B1")
EndDate = Sheets("Macro Data").Cells("B2")

Then I am going to use StartDate and EndDate in the AutoFilter statement
that I gave in my previous message. However, the above statements are giving
me error 13 (type mismatch). Can you help me with what's wrong with what I'm
doing? Thanks!

Dan
 

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

Back
Top