PC Review


Reply
Thread Tools Rate Thread

Auto Filter-VB

 
 
=?Utf-8?B?Q2xpbnQgRWFzdHdvb2Q=?=
Guest
Posts: n/a
 
      7th Nov 2007
Can you use Auto Filter w VB to display only certain years in a spreadsheet
?? I have 3 columns/70 rows with 4 different years ( MM/DD/YYYY). I'm
trying to figure out how to set the auto filter to only show 2007 , do some
calculations then only display 2008, do some calculations etc. using VB

Selection.AutoFilter Field:=1, Criteria1:="2007"

Thanks,
Clint
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      7th Nov 2007
Ron de Bruin pointed me to a way that works for him (he can have a problem with
international issues).

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("A1200").AutoFilter 2, ">=02/01/2001", xlAnd, "<=02/01/2001"

======================
So you should be able to show dates by looking at Jan 1st through Dec 31.



Clint Eastwood wrote:
>
> Can you use Auto Filter w VB to display only certain years in a spreadsheet
> ?? I have 3 columns/70 rows with 4 different years ( MM/DD/YYYY). I'm
> trying to figure out how to set the auto filter to only show 2007 , do some
> calculations then only display 2008, do some calculations etc. using VB
>
> Selection.AutoFilter Field:=1, Criteria1:="2007"
>
> Thanks,
> Clint


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Filter - Custom Auto Filter Johnnyboy5 Microsoft Excel Programming 4 2nd Aug 2009 09:36 AM
Data>Filter>Auto Filter in excel 2007? TIJ Microsoft Excel New Users 2 13th Nov 2008 03:28 AM
Excel 2007 Auto Filter Filter Django Microsoft Excel Misc 2 9th Sep 2008 10:52 PM
Limit filter options in Auto Filter lista72 Microsoft Excel Misc 1 23rd Jan 2008 04:01 PM
Excel auto filter doesn't recoginize case - won't filter AA from A =?Utf-8?B?TWlrZXk=?= Microsoft Excel Misc 1 29th Sep 2005 08:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:32 PM.