View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Nigel[_2_] Nigel[_2_] is offline
external usenet poster
 
Posts: 735
Default Excel! How can I use a variable in an autofilter in VBA?

Try
Criteria1:="=" & StartDate

--

Regards,
Nigel




"alskdjfhgzmxncbv" wrote in
message ...
I want to use a variable as the criteria for an autofilter.
What I have is this:
ActiveSheet.Range("$A$1:$S$277").AutoFilter Field:=1,
Criteria1:="=StartDate", Operator:=xlAnd, Criteria2:="<=EndDate"
where StartDate and EndDate would be assigned date values to filter
between
those dates. Results are no records as the variable name is used instead
of
the value of the variable.
Variables are dim'ed as variants.
Thanks.