Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Gus
 
Posts: n/a
Default macro for 4 constraints in autofilter

Hi

Not sure if this is possible, or if I have tackled this the right way so any
help greatly appreciated! I am (trying to) write a macro that will use
multiple constraints (in 1 column) in autofilter, this is so that I don't
have to use the advanced filter option. The result of the macro should return
rows that contain "19" or "20" or "act" or "regul" in the 3rd field, and hide
the rows that don't. My macro that is not working at the moment:

'
Sheets("Agr-Tra").Select
Selection.AutoFilter Field:=3, Criteria1:="=regul*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=act*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=19*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=20*"
End Sub

This is returning 0 rows with the above criteria, which is incorrect as it
should be over 300 rows.

Much appreciated
Gus
  #2   Report Post  
bj
 
Posts: n/a
Default

You dont need a macro
the simplest way to do this is to set up a helper column with
=if(or(C1=19,C1=20,C1="act",C1="regul"),1,0)
and use normal autofilter on this column.

"Gus" wrote:

Hi

Not sure if this is possible, or if I have tackled this the right way so any
help greatly appreciated! I am (trying to) write a macro that will use
multiple constraints (in 1 column) in autofilter, this is so that I don't
have to use the advanced filter option. The result of the macro should return
rows that contain "19" or "20" or "act" or "regul" in the 3rd field, and hide
the rows that don't. My macro that is not working at the moment:

'
Sheets("Agr-Tra").Select
Selection.AutoFilter Field:=3, Criteria1:="=regul*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=act*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=19*", Operator:=xlOr
Selection.AutoFilter Field:=3, Criteria1:="=20*"
End Sub

This is returning 0 rows with the above criteria, which is incorrect as it
should be over 300 rows.

Much appreciated
Gus

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
Keep autofilter after macro is run gmr7 Excel Worksheet Functions 2 July 5th 05 02:16 PM
Macro for autofilter using variables declared in worksheet Jeff Excel Worksheet Functions 2 June 14th 05 04:38 AM
how to write macro after autofilter is applied emre Excel Worksheet Functions 2 March 31st 05 03:59 PM
Loop Macro autofilter Paul. Excel Discussion (Misc queries) 2 March 25th 05 10:35 AM
Autofilter Macro Help RonB Excel Discussion (Misc queries) 1 December 30th 04 02:34 AM


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