Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Semi Autofilter code

rng.AutoFilter
rng.AutoFilter Field:=1, Criteria1:="=" & dtStart, Operator:=xlAnd, _
Criteria2:="<=" & dtEnd
.................................................. ..................

Above code should filter some data but only places dates in custom
window and nothing else.
Having run the code I checked the custom window of column1 and I found
that the dates are respectively there and correct. Just press OK
button and bingo ! Desired result appears.
Am I missing something here to activate OK button ?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Semi Autofilter code

Try the technique I use:

Start recording a macro, manually do the piece that's missing (in this
case, record the steps you describe), stop recording and examine the
resulting code.

The recorded macro code should supply the answer you are seeking.

HTH!
Clif

wrote in message
...
rng.AutoFilter
rng.AutoFilter Field:=1, Criteria1:="=" & dtStart, Operator:=xlAnd, _
Criteria2:="<=" & dtEnd
.................................................. .................

Above code should filter some data but only places dates in custom
window and nothing else.
Having run the code I checked the custom window of column1 and I found
that the dates are respectively there and correct. Just press OK
button and bingo ! Desired result appears.
Am I missing something here to activate OK button ?
Thanks




--
Clif McIrvin

Change nomail.afraid.org to gmail.com to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Semi Autofilter code

Try:

rng.AutoFilter Field:=1, _
Criteria1:="=" & format(dtStart, "mm/dd/yyyy"), Operator:=xlAnd, _
Criteria2:="<=" & format(dtEnd, "mm/dd/yyyy")

Assuming that dtStart and dtEnd are really dates.

Saved from a previous post:

This is from "Excel 2002 VBA Programmer's Reference"
Written by John Green, Stephen Bullen, Rob Bovey and Robert Rosenberg

http://www.oaltd.co.uk:80/ExcelProgR...rogRefCh22.htm
Search for "Range.AutoFilter" and you'll see this note:

Range.AutoFilter

The AutoFilter method of a Range object is a very curious beast. We are forced
to pass it strings for its filter criteria and hence must be aware of its string
handling behaviour. The criteria string consists of an operator (=, , <, =
etc.) followed by a value.

If no operator is specified, the "=" operator is assumed. The key issue is that
when using the "=" operator, AutoFilter performs a textual match, while using
any other operator results in a match by value. This gives us problems when
trying to locate exact matches for dates and numbers.

If we use "=", Excel matches on the text that is displayed in the cell, i.e. the
formatted number. As the text displayed in a cell will change with different
regional settings and Windows language version, it is impossible for us to
create a criteria string that will locate an exact match in all locales.

There is a workaround for this problem. When using any of the other filter
criteria, Excel plays by the rules and interprets the criteria string according
to US formats. Hence, a search criterion of "=02/01/2001" will find all dates
on or after 1st Feb, 2001, in all locales.

We can use this to match an exact date by using two AutoFilter criteria. The
following code will give an exact match on 1st Feb, 2001 and will work in any
locale:

Range("A1:D200").AutoFilter 2, "=02/01/2001", xlAnd, "<=02/01/2001"


On 10/11/2010 13:53, wrote:
rng.AutoFilter
rng.AutoFilter Field:=1, Criteria1:="="& dtStart, Operator:=xlAnd, _
Criteria2:="<="& dtEnd
.................................................. .................

Above code should filter some data but only places dates in custom
window and nothing else.
Having run the code I checked the custom window of column1 and I found
that the dates are respectively there and correct. Just press OK
button and bingo ! Desired result appears.
Am I missing something here to activate OK button ?
Thanks


--
Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Semi Autofilter code

Thank you Dave and the authors of sNumToUS Function here
http://www.oaltd.co.uk:80/ExcelProgR...rogRefCh22.htm
This finally worked:

Selection.AutoFilter 1, "=" & sNumToUS(dtStart), xlAnd, "<=" &
sNumToUS(dtEnd)

Curious though when I set an area as filter range it doesn't work,
like below.

rng.AutoFilter 1, "=" & sNumToUS(dtStart), xlAnd, "<=" &
sNumToUS(dtEnd)

Many thanks to you all for your help.
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
vba code on autofilter ub Excel Discussion (Misc queries) 1 August 6th 08 08:09 PM
Autofilter code Dominic LeVasseur Excel Discussion (Misc queries) 2 August 16th 06 09:33 PM
looking for autofilter with code lcoreyl[_15_] Excel Programming 1 September 24th 04 01:38 PM
looking for autofilter with code lcoreyl[_13_] Excel Programming 0 September 23rd 04 12:57 AM
looking for autofilter with code lcoreyl[_12_] Excel Programming 3 September 22nd 04 02:36 PM


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

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"