![]() |
VBA Code for Custom Date Filter
Hi
I am using Excel 2003 and what to do a custom filter on a date range through VBA. I am using the code below but when I look at the sheet no data is displayed if I look at the custom filter option on the field the setting are there and if I click on OK the data will then display. It is like the custom filter through the code is not be executed / refreshed but the criteria is going into the correct place. Sub DateFilter() vFilter = Range("DateAssigned").Value vFilter2 = Range("DateAssigned2").Value Sheets("DCR").Select Selection.AutoFilter Field:=2, Criteria1:="=" & Format(vFilter, "dd/mm/yyyy"), Operator:= _ xlAnd, Criteria2:="<=" & Format(vFilter2, "dd/mm/yyyy") End sub Thanks Ailish |
VBA Code for Custom Date Filter
Hi Ailish
Use the US format in the code mm/dd/yyyy No problem if the format in the data is different -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Ailish" wrote in message ... Hi I am using Excel 2003 and what to do a custom filter on a date range through VBA. I am using the code below but when I look at the sheet no data is displayed if I look at the custom filter option on the field the setting are there and if I click on OK the data will then display. It is like the custom filter through the code is not be executed / refreshed but the criteria is going into the correct place. Sub DateFilter() vFilter = Range("DateAssigned").Value vFilter2 = Range("DateAssigned2").Value Sheets("DCR").Select Selection.AutoFilter Field:=2, Criteria1:="=" & Format(vFilter, "dd/mm/yyyy"), Operator:= _ xlAnd, Criteria2:="<=" & Format(vFilter2, "dd/mm/yyyy") End sub Thanks Ailish |
VBA Code for Custom Date Filter
Yes fantastic Ron thanks for the quick reply.
"Ron de Bruin" wrote: Hi Ailish Use the US format in the code mm/dd/yyyy No problem if the format in the data is different -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Ailish" wrote in message ... Hi I am using Excel 2003 and what to do a custom filter on a date range through VBA. I am using the code below but when I look at the sheet no data is displayed if I look at the custom filter option on the field the setting are there and if I click on OK the data will then display. It is like the custom filter through the code is not be executed / refreshed but the criteria is going into the correct place. Sub DateFilter() vFilter = Range("DateAssigned").Value vFilter2 = Range("DateAssigned2").Value Sheets("DCR").Select Selection.AutoFilter Field:=2, Criteria1:="=" & Format(vFilter, "dd/mm/yyyy"), Operator:= _ xlAnd, Criteria2:="<=" & Format(vFilter2, "dd/mm/yyyy") End sub Thanks Ailish |
All times are GMT +1. The time now is 05:12 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com