ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code to filter a database displays no rows at all (https://www.excelbanter.com/excel-programming/401101-code-filter-database-displays-no-rows-all.html)

Pete Rooney

Code to filter a database displays no rows at all
 
Good afternoon!

I recorded a macro to filter a database to show records where the entry in
column 1 was between two dates thus:

Sub DateFilterOn()
Range("MainDatabaseStart").AutoFilter Field:=1, _
Criteria1:="=23/10/2007", Operator:=xlAnd, _
Criteria2:="<=22/11/2007"
End Sub

When I run the code, it filters the database down and displays no rows at
all (which is incorrect, as there are loads of them that meet the criteria).
If I then go into Data Filter Custom manually on the first DB column, the
criteria from the code appear in the dialog box and when I click "OK", the
database is correctly filtered.

Can anyone tell me where I'm going wrong, please? Why won't my code filter
my data correctly without the manual intervention?

Thanks in advance.

pete

Ron de Bruin

Code to filter a database displays no rows at all
 
Hi Pete

Use the US date format mm/dd/yyyy instead of the DMY you use now in the code



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Pete Rooney" wrote in message ...
Good afternoon!

I recorded a macro to filter a database to show records where the entry in
column 1 was between two dates thus:

Sub DateFilterOn()
Range("MainDatabaseStart").AutoFilter Field:=1, _
Criteria1:="=23/10/2007", Operator:=xlAnd, _
Criteria2:="<=22/11/2007"
End Sub

When I run the code, it filters the database down and displays no rows at
all (which is incorrect, as there are loads of them that meet the criteria).
If I then go into Data Filter Custom manually on the first DB column, the
criteria from the code appear in the dialog box and when I click "OK", the
database is correctly filtered.

Can anyone tell me where I'm going wrong, please? Why won't my code filter
my data correctly without the manual intervention?

Thanks in advance.

pete


Pete Rooney

Code to filter a database displays no rows at all
 
Ron,

Nice to hear from you again!

As usual, spot on answer :-)

Thank you!

Pete

"Ron de Bruin" wrote:

Hi Pete

Use the US date format mm/dd/yyyy instead of the DMY you use now in the code



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Pete Rooney" wrote in message ...
Good afternoon!

I recorded a macro to filter a database to show records where the entry in
column 1 was between two dates thus:

Sub DateFilterOn()
Range("MainDatabaseStart").AutoFilter Field:=1, _
Criteria1:="=23/10/2007", Operator:=xlAnd, _
Criteria2:="<=22/11/2007"
End Sub

When I run the code, it filters the database down and displays no rows at
all (which is incorrect, as there are loads of them that meet the criteria).
If I then go into Data Filter Custom manually on the first DB column, the
criteria from the code appear in the dialog box and when I click "OK", the
database is correctly filtered.

Can anyone tell me where I'm going wrong, please? Why won't my code filter
my data correctly without the manual intervention?

Thanks in advance.

pete




All times are GMT +1. The time now is 09:09 AM.

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