View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default How to Filter Date?

Sometimes this works:

FilterDate = clng(Range("C1")) '10/01/98
or equivalently
Selection.AutoFilter Field:=11, Criteria1:="<=" & clng(dateserial(1998,10,1))




Jan Nademlejnsky wrote:

I need to create macro which will pick a date from C1 and then select all
records with dates <= than this date. Also my date format shown is mm/dd/yy,
but when read into FilterDate it is in mm/dd/yyyy. Is there any way to force
FilterDate into mm/dd/yy?

See example, please. I am struggling with the & and """ order. I need to fix
the last line
C1 and Column 11 (Field 11) are formatted mm/dd/yy

Dim FilterDate as Date
Sub test()
FilterDate = Range("C1") '10/01/98
Range("K3").Select
Application.CutCopyMode = False
'Selection.AutoFilter Field:=11, Criteria1:="<=10/01/1998"
'Selection.AutoFilter Field:=11, Criteria1:=FilterDate ' this works
Selection.AutoFilter Field:=11, Criteria1:="&" <= "&FilterDate" 'this
does not work
End Sub

Thanks for your help

Jan


--

Dave Peterson