davidtrickett
New Member
- Joined
- Apr 22, 2002
- Messages
- 37
I have a very large worksheet - autofilter is on and data are in range A4-Y45000(and growing!). Headers are on row 4.
Column U contains dates.
I need some code to filter on a selected date, and on or after it.
Everything I have is set up for the UK date format - i.e. today is 05/08/2017.
The date column is formatted to dd-mmm
So if I select say 15th May the cell displays 15-May, and the edit box shows 15/05/2017
In theory this should work:
But what it does is filter out all non-blank cells! It seems that instead of filtering on 15/05/2017 it is trying to do so on the US date format - 05/15/2017, and since there is no such date it returns nothing.
Stupid ****** machine!
This does work:
To filter on or after change the autofilter line to:
But this is really clumsy & inelegant.
Is there any way of persuading vba to believe that 15/05/2017 means May 15th 2017?
Incidentally I have come across the same problem in other contexts, so any helpful answer will have wider application.
Thanks
Column U contains dates.
I need some code to filter on a selected date, and on or after it.
Everything I have is set up for the UK date format - i.e. today is 05/08/2017.
The date column is formatted to dd-mmm
So if I select say 15th May the cell displays 15-May, and the edit box shows 15/05/2017
In theory this should work:
Code:
Selection.AutoFilter Field:=21, Criteria1:=ActiveCell.Value
But what it does is filter out all non-blank cells! It seems that instead of filtering on 15/05/2017 it is trying to do so on the US date format - 05/15/2017, and since there is no such date it returns nothing.
Stupid ****** machine!
This does work:
Code:
Application.ScreenUpdating = False
lastrow = Cells(80000, "u").End(xlUp).Row
If ActiveCell.Column <> 21 Then Exit Sub
If ActiveCell.Row < 4 Then Exit Sub
If ActiveCell.Row > lastrow Then Exit Sub
'Now change column format to date serials - e.g. 42870
Range("U4:U" & lastrow).NumberFormat = ("0")
'Data Filter is already active on this worksheet
Selection.AutoFilter Field:=21, Criteria1:=ActiveCell.Value
'Change format back
Range("U4:U" & lastrow).NumberFormat = ("dd-mmm")
Application.ScreenUpdating = True
To filter on or after change the autofilter line to:
Code:
Selection.AutoFilter Field:=21, Criteria1:=">=" & ActiveCell.Value
But this is really clumsy & inelegant.
Is there any way of persuading vba to believe that 15/05/2017 means May 15th 2017?
Incidentally I have come across the same problem in other contexts, so any helpful answer will have wider application.
Thanks