Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Filter based on Date

Hi,

Always I face a problem when i try to filter a range based on date. If
I do it manually it works fine. But when I try to do this thru code it
dont work.

May be there is a better way to do this?

when I recoded my action i get:

Sheets("Detail").select
Range("A1").AutoFilter Field:=1, Criteria1:="=01/07/2006",
Operator:=xlAnd _
, Criteria2:="<=31/07/2006"

and when i run this code again no records are shown !!!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Filter based on Date

Damn US dates <g

Dim date1_value As Date
Dim date2_value As Date

Sheets("Detail").Select
date1_value = DateValue("01-Jul-2006")
date2_value = DateValue("31-Jul-2006")
Range("A1").AutoFilter Field:=1, _
Criteria1:="=" & Str(CDbl(date1_value)), _
Operator:=xlAnd, _
Criteria2:="<=" & Str(CDbl(date2_value))


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Abdul" wrote in message
oups.com...
Hi,

Always I face a problem when i try to filter a range based on date. If
I do it manually it works fine. But when I try to do this thru code it
dont work.

May be there is a better way to do this?

when I recoded my action i get:

Sheets("Detail").select
Range("A1").AutoFilter Field:=1, Criteria1:="=01/07/2006",
Operator:=xlAnd _
, Criteria2:="<=31/07/2006"

and when i run this code again no records are shown !!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Filter based on Date

Just wondering, is it necessary to do all that or simply

Range("A1").AutoFilter Field:=1, _
Criteria1:="=07/Jul/2006", _
Operator:=xlAnd _
, Criteria2:="<=31/Aug/2006"

as long as the month is spelt and in US date order

Regards,
Peter T

"Bob Phillips" wrote in message
...
Damn US dates <g

Dim date1_value As Date
Dim date2_value As Date

Sheets("Detail").Select
date1_value = DateValue("01-Jul-2006")
date2_value = DateValue("31-Jul-2006")
Range("A1").AutoFilter Field:=1, _
Criteria1:="=" & Str(CDbl(date1_value)), _
Operator:=xlAnd, _
Criteria2:="<=" & Str(CDbl(date2_value))


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Abdul" wrote in message
oups.com...
Hi,

Always I face a problem when i try to filter a range based on date. If
I do it manually it works fine. But when I try to do this thru code it
dont work.

May be there is a better way to do this?

when I recoded my action i get:

Sheets("Detail").select
Range("A1").AutoFilter Field:=1, Criteria1:="=01/07/2006",
Operator:=xlAnd _
, Criteria2:="<=31/07/2006"

and when i run this code again no records are shown !!!





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Filter based on Date

Hi Peter,

My suggestion was more of a generic solution. It should work wherever you
get the date from, a cell, a userform etc., and filter correctly. You have
effectively shortcut my solution for those particular dates.

Regards

Bob

"Peter T" <peter_t@discussions wrote in message
...
Just wondering, is it necessary to do all that or simply

Range("A1").AutoFilter Field:=1, _
Criteria1:="=07/Jul/2006", _
Operator:=xlAnd _
, Criteria2:="<=31/Aug/2006"

as long as the month is spelt and in US date order

Regards,
Peter T

"Bob Phillips" wrote in message
...
Damn US dates <g

Dim date1_value As Date
Dim date2_value As Date

Sheets("Detail").Select
date1_value = DateValue("01-Jul-2006")
date2_value = DateValue("31-Jul-2006")
Range("A1").AutoFilter Field:=1, _
Criteria1:="=" & Str(CDbl(date1_value)), _
Operator:=xlAnd, _
Criteria2:="<=" & Str(CDbl(date2_value))


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Abdul" wrote in message
oups.com...
Hi,

Always I face a problem when i try to filter a range based on date. If
I do it manually it works fine. But when I try to do this thru code it
dont work.

May be there is a better way to do this?

when I recoded my action i get:

Sheets("Detail").select
Range("A1").AutoFilter Field:=1, Criteria1:="=01/07/2006",
Operator:=xlAnd _
, Criteria2:="<=31/07/2006"

and when i run this code again no records are shown !!!







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Filter based on Date

Hi Bob,

I have always found that providing a date string is un-ambiguous it
correctly converts. Not sure about the "-" as date separator in all systems
(but "/" is always OK), also not sure if "July" is recognized in all
languages. But I see your solution would be better practice, I'll try not
to be lazy <g

Regards,
Peter T

"Bob Phillips" wrote in message
...
Hi Peter,

My suggestion was more of a generic solution. It should work wherever you
get the date from, a cell, a userform etc., and filter correctly. You have
effectively shortcut my solution for those particular dates.

Regards

Bob

"Peter T" <peter_t@discussions wrote in message
...
Just wondering, is it necessary to do all that or simply

Range("A1").AutoFilter Field:=1, _
Criteria1:="=07/Jul/2006", _
Operator:=xlAnd _
, Criteria2:="<=31/Aug/2006"

as long as the month is spelt and in US date order

Regards,
Peter T

"Bob Phillips" wrote in message
...
Damn US dates <g

Dim date1_value As Date
Dim date2_value As Date

Sheets("Detail").Select
date1_value = DateValue("01-Jul-2006")
date2_value = DateValue("31-Jul-2006")
Range("A1").AutoFilter Field:=1, _
Criteria1:="=" & Str(CDbl(date1_value)), _
Operator:=xlAnd, _
Criteria2:="<=" & Str(CDbl(date2_value))


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Abdul" wrote in message
oups.com...
Hi,

Always I face a problem when i try to filter a range based on date.

If
I do it manually it works fine. But when I try to do this thru code

it
dont work.

May be there is a better way to do this?

when I recoded my action i get:

Sheets("Detail").select
Range("A1").AutoFilter Field:=1, Criteria1:="=01/07/2006",
Operator:=xlAnd _
, Criteria2:="<=31/07/2006"

and when i run this code again no records are shown !!!











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 380
Default Filter based on Date

Peter,

I absolutely agree about unambiguous dates. When I use is SUMPRODUCT
solutions I try to use an ISO standard yyyy-mm-dd, I haven't yet heard from
anyone that "-" is a problem. And certainly July would not be recognised in
Excel with our friends across the channel.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Peter T" <peter_t@discussions wrote in message
...
Hi Bob,

I have always found that providing a date string is un-ambiguous it
correctly converts. Not sure about the "-" as date separator in all

systems
(but "/" is always OK), also not sure if "July" is recognized in all
languages. But I see your solution would be better practice, I'll try not
to be lazy <g

Regards,
Peter T

"Bob Phillips" wrote in message
...
Hi Peter,

My suggestion was more of a generic solution. It should work wherever

you
get the date from, a cell, a userform etc., and filter correctly. You

have
effectively shortcut my solution for those particular dates.

Regards

Bob

"Peter T" <peter_t@discussions wrote in message
...
Just wondering, is it necessary to do all that or simply

Range("A1").AutoFilter Field:=1, _
Criteria1:="=07/Jul/2006", _
Operator:=xlAnd _
, Criteria2:="<=31/Aug/2006"

as long as the month is spelt and in US date order

Regards,
Peter T

"Bob Phillips" wrote in message
...
Damn US dates <g

Dim date1_value As Date
Dim date2_value As Date

Sheets("Detail").Select
date1_value = DateValue("01-Jul-2006")
date2_value = DateValue("31-Jul-2006")
Range("A1").AutoFilter Field:=1, _
Criteria1:="=" & Str(CDbl(date1_value)), _
Operator:=xlAnd, _
Criteria2:="<=" & Str(CDbl(date2_value))


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Abdul" wrote in message
oups.com...
Hi,

Always I face a problem when i try to filter a range based on

date.
If
I do it manually it works fine. But when I try to do this thru

code
it
dont work.

May be there is a better way to do this?

when I recoded my action i get:

Sheets("Detail").select
Range("A1").AutoFilter Field:=1, Criteria1:="=01/07/2006",
Operator:=xlAnd _
, Criteria2:="<=31/07/2006"

and when i run this code again no records are shown !!!











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro filter based on date criteria puiuluipui Excel Discussion (Misc queries) 4 September 19th 09 12:18 PM
Filter latest date from multiple date entries [email protected] Excel Worksheet Functions 1 July 4th 08 09:40 PM
Dupliate names with different date Filter for newest date Becky Excel Discussion (Misc queries) 1 April 8th 07 08:38 PM
Sumproduct based which also weights data based on date ExcelMonkey Excel Worksheet Functions 6 February 4th 07 08:51 AM
copy date based on date -refer to date range mindpeace[_4_] Excel Programming 1 June 3rd 06 01:30 PM


All times are GMT +1. The time now is 04:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"