View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Why won't it work when I use VBA to set autofilter criteria to ce.

Dim sStartDate As Date
Dim sEndDate As Date
Dim sBottomRow As String
sStartDate = Sheets("Data").Cells(6, 2).Value
sEndDate = Sheets("Data").Cells(6, 4).Value
sBottomRow = CStr(Sheets("Data").Range("B8").End(xlDown).Row)
Selection.AutoFilter Field:=8, _
Criteria1:="=" & sStartDate, _
Operator:=xlAnd, _
Criteria2:="<=" & sEndDate

if that doesn't work modify the above to

Selection.AutoFilter Field:=8, _
Criteria1:="=" & clng(sStartDate), _
Operator:=xlAnd, _
Criteria2:="<=" & clng(sEndDate)


--
Regards,
Tom Ogilvy


"biggy" wrote in message
...
Below is an example of what I had programmed for a custom autofilter. The
cells in the criteria contain dates. When I run the Macro it hides all the
data. However if I then go into the custom filter manually the dates are
already entered in the criteria and I just have to press OK for the filter

to
work. Is there a way around having to do this manually or can excel not
handle this sort of functionality?

Dim sStartDate As String
Dim sEndDate As String
Dim sBottomRow As String

sStartDate = Sheets("Data").Cells(6, 2).Value
sEndDate = Sheets("Data").Cells(6, 4).Value
sBottomRow = CStr(Sheets("Data").Range("B8").End(xlDown).Row)


Selection.AutoFilter Field:=8, Criteria1:="=" & sStartDate,
Operator:= _
xlAnd, Criteria2:="<=" & sEndDate