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

I have an autofilter with a column of data that includes operators such as
and <.

For example, one of the records would read " 60 days past due"

How would I go about coding the criteria to show the records that display "
60 days past due"?

Thanks,
Chad
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Autofilter question

Macro recorder returns this.

Selection.AutoFilter Field:=1, Criteria1:="= 60 days past due"


Gord Dibben MS Excel MVP


On Mon, 26 Apr 2010 13:23:01 -0700, Chad
wrote:

I have an autofilter with a column of data that includes operators such as
and <.

For example, one of the records would read " 60 days past due"

How would I go about coding the criteria to show the records that display "
60 days past due"?

Thanks,
Chad


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Autofilter question

In Excel 2007 the macro recorder does not return the equal sign. The
following is what I get with the macro recorder. I have not tested in any
other versions.

ActiveSheet.Range("$A$1:$B$835").AutoFilter Field:=2, Criteria1:= _
" 60 days past due"

And of course the above does not work without the leading = sign when the
code is run.

--
Regards,

OssieMac


"Gord Dibben" wrote:

Macro recorder returns this.

Selection.AutoFilter Field:=1, Criteria1:="= 60 days past due"


Gord Dibben MS Excel MVP


On Mon, 26 Apr 2010 13:23:01 -0700, Chad
wrote:

I have an autofilter with a column of data that includes operators such as
and <.

For example, one of the records would read " 60 days past due"

How would I go about coding the criteria to show the records that display "
60 days past due"?

Thanks,
Chad


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Autofilter question

My testing was on 2003.

I have since tested on 2007 and found that you get different results
depending upon how you filter.

Selecting from the list you get

ActiveSheet.Range("$A$1:$A$22").AutoFilter Field:=1, Criteria1:="60 days"

Selecting from CustomEquals you get

ActiveSheet.Range("$A$1:$A$22").AutoFilter Field:=1, Criteria1:="=60 days"

2003 treats both methods the same and returns in both cases

ActiveSheet.Range("$A$1:$A$22").AutoFilter Field:=1, Criteria1:="=60 days"



Gord

On Mon, 26 Apr 2010 15:43:02 -0700, OssieMac
wrote:

In Excel 2007 the macro recorder does not return the equal sign. The
following is what I get with the macro recorder. I have not tested in any
other versions.

ActiveSheet.Range("$A$1:$B$835").AutoFilter Field:=2, Criteria1:= _
" 60 days past due"

And of course the above does not work without the leading = sign when the
code is run.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Autofilter question

Hi chad,

I am assuming that you tried recording this and while the filter worked in
the interactive mode; when you run the code it does not work. The answer is
to insert a leading equal sign.

"=60 days past due"

A tip for these things is the following code. Set the filter then run the
code and you will be able to see the criteria that needs to be used for the
code.

Dim strCriteria

With Worksheets("Sheet1")
If .AutoFilterMode Then
With .AutoFilter.Filters(2)
If .On Then strCriteria = .Criteria1
End With
End If
End With

MsgBox strCriteria


--
Regards,

OssieMac


"Chad" wrote:

I have an autofilter with a column of data that includes operators such as
and <.

For example, one of the records would read " 60 days past due"

How would I go about coding the criteria to show the records that display "
60 days past due"?

Thanks,
Chad



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Autofilter question

Ossie

When I record, Excel adds the appropriate "=60 days past due"


Gord

On Mon, 26 Apr 2010 14:30:01 -0700, OssieMac
wrote:

Hi chad,

I am assuming that you tried recording this and while the filter worked in
the interactive mode; when you run the code it does not work. The answer is
to insert a leading equal sign.

"=60 days past due"

A tip for these things is the following code. Set the filter then run the
code and you will be able to see the criteria that needs to be used for the
code.

Dim strCriteria

With Worksheets("Sheet1")
If .AutoFilterMode Then
With .AutoFilter.Filters(2)
If .On Then strCriteria = .Criteria1
End With
End If
End With

MsgBox strCriteria


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
AutoFilter Question Ram Excel Discussion (Misc queries) 6 November 27th 06 04:05 PM
Autofilter question MikeG22 Excel Programming 5 October 10th 06 08:45 PM
AutoFilter Question AccessHelp Excel Discussion (Misc queries) 2 September 29th 06 09:25 PM
AUTOFILTER QUESTION Dan Excel Programming 1 March 2nd 05 04:36 PM
AutoFilter question Alex Sossick Excel Programming 0 January 21st 04 05:07 PM


All times are GMT +1. The time now is 04:00 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"