ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Filter Date? (https://www.excelbanter.com/excel-programming/302818-how-filter-date.html)

Jan Nademlejnsky[_2_]

How to Filter Date?
 
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[_3_]

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



All times are GMT +1. The time now is 10:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com