Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Macro filter multiple criterea

Hello,

I've been searching the forum for a while but i cant find a right solution.
I have this macro:

Sub filter()

Sheets("KAM").Select
Selection.AutoFilter Field:=12, Criteria1:="=ANLAGE", Operator:=xlOr, _
Criteria2:="=PE", Operator:=xlOr, _
Criteria3:="=ED03"
End Sub

I would like to have a macro that filters multiple criterea (e.g. "ANLAGE",
"PE", "ED03"... etc) The first two was no problem but when i wanted to add a
third one and a fourth one it gives an error.

In the end i would like to have two buttons that are attached to the macro.
When clicking the button it show different filtered lists

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Macro filter multiple criterea

TooN,

You cannot have more than two criteria with Autofilter, I would use the
following:

Sub filter()
Sheets("KAM").Select
Range("A1:M30").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:=Range("N1:N4"), Unique:=False
End Sub

Range("A1:M30") would be the extent of you data and Range("N1:N4") would
contain you column heading and criteria (N1 would be the column heading in
column 12, N2 would be ANLAGE, N3 would be PE and N4 would be ED03).

Not quite sure what you mean by having two buttons though.

Hope this helps.

Gareth

"TooN" wrote:

Hello,

I've been searching the forum for a while but i cant find a right solution.
I have this macro:

Sub filter()

Sheets("KAM").Select
Selection.AutoFilter Field:=12, Criteria1:="=ANLAGE", Operator:=xlOr, _
Criteria2:="=PE", Operator:=xlOr, _
Criteria3:="=ED03"
End Sub

I would like to have a macro that filters multiple criterea (e.g. "ANLAGE",
"PE", "ED03"... etc) The first two was no problem but when i wanted to add a
third one and a fourth one it gives an error.

In the end i would like to have two buttons that are attached to the macro.
When clicking the button it show different filtered lists

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro filter multiple criterea

Suppose your data in active sheet..Data range is ColA/ColB A1:B10..Filter
criteria
range is C1:C3 (with header)

Col A Col B Col C
Header 1 Header 2 Header 1
a 1 a
a 2 b
b 3
a 4
b 5
c 6
d 7
e 8
a 9

Sub Macro2()
Range("A1:B10").AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=Range("C1:C3"), Unique:=False
End Sub


--
Jacob


"TooN" wrote:

Hello,

I've been searching the forum for a while but i cant find a right solution.
I have this macro:

Sub filter()

Sheets("KAM").Select
Selection.AutoFilter Field:=12, Criteria1:="=ANLAGE", Operator:=xlOr, _
Criteria2:="=PE", Operator:=xlOr, _
Criteria3:="=ED03"
End Sub

I would like to have a macro that filters multiple criterea (e.g. "ANLAGE",
"PE", "ED03"... etc) The first two was no problem but when i wanted to add a
third one and a fourth one it gives an error.

In the end i would like to have two buttons that are attached to the macro.
When clicking the button it show different filtered lists

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro filter multiple criterea

You could add another helper column that contains a formula that evaluates to
true/false. Then filter on that column.

The formula could be as simple as something like:

=or(a2="hi",a2="bye",a2="there")
or this equivalent:
=or(a2={"hi","bye","there"})

Or it could be as complex as you need.

Or you could learn about advanced filtering and criteria ranges.

I'd start at Debra Dalgleish's site:
http://contextures.com/xladvfilter01.html

TooN wrote:

Hello,

I've been searching the forum for a while but i cant find a right solution.
I have this macro:

Sub filter()

Sheets("KAM").Select
Selection.AutoFilter Field:=12, Criteria1:="=ANLAGE", Operator:=xlOr, _
Criteria2:="=PE", Operator:=xlOr, _
Criteria3:="=ED03"
End Sub

I would like to have a macro that filters multiple criterea (e.g. "ANLAGE",
"PE", "ED03"... etc) The first two was no problem but when i wanted to add a
third one and a fourth one it gives an error.

In the end i would like to have two buttons that are attached to the macro.
When clicking the button it show different filtered lists

Thanks


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Macro filter multiple criterea

Have you ever seen this tool?
http://www.mediafire.com/?5tmfjngnymz

Type some criteria in row 1 and the tool will auto-filter. That may give
you some ideas.

HTH,
Ryan--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Dave Peterson" wrote:

You could add another helper column that contains a formula that evaluates to
true/false. Then filter on that column.

The formula could be as simple as something like:

=or(a2="hi",a2="bye",a2="there")
or this equivalent:
=or(a2={"hi","bye","there"})

Or it could be as complex as you need.

Or you could learn about advanced filtering and criteria ranges.

I'd start at Debra Dalgleish's site:
http://contextures.com/xladvfilter01.html

TooN wrote:

Hello,

I've been searching the forum for a while but i cant find a right solution.
I have this macro:

Sub filter()

Sheets("KAM").Select
Selection.AutoFilter Field:=12, Criteria1:="=ANLAGE", Operator:=xlOr, _
Criteria2:="=PE", Operator:=xlOr, _
Criteria3:="=ED03"
End Sub

I would like to have a macro that filters multiple criterea (e.g. "ANLAGE",
"PE", "ED03"... etc) The first two was no problem but when i wanted to add a
third one and a fourth one it gives an error.

In the end i would like to have two buttons that are attached to the macro.
When clicking the button it show different filtered lists

Thanks


--

Dave Peterson
.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro filter multiple criterea

Nope. But I don't download or open files from sources I don't know.

ryguy7272 wrote:

Have you ever seen this tool?
http://www.mediafire.com/?5tmfjngnymz

Type some criteria in row 1 and the tool will auto-filter. That may give
you some ideas.

HTH,
Ryan--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.

"Dave Peterson" wrote:

You could add another helper column that contains a formula that evaluates to
true/false. Then filter on that column.

The formula could be as simple as something like:

=or(a2="hi",a2="bye",a2="there")
or this equivalent:
=or(a2={"hi","bye","there"})

Or it could be as complex as you need.

Or you could learn about advanced filtering and criteria ranges.

I'd start at Debra Dalgleish's site:
http://contextures.com/xladvfilter01.html

TooN wrote:

Hello,

I've been searching the forum for a while but i cant find a right solution.
I have this macro:

Sub filter()

Sheets("KAM").Select
Selection.AutoFilter Field:=12, Criteria1:="=ANLAGE", Operator:=xlOr, _
Criteria2:="=PE", Operator:=xlOr, _
Criteria3:="=ED03"
End Sub

I would like to have a macro that filters multiple criterea (e.g. "ANLAGE",
"PE", "ED03"... etc) The first two was no problem but when i wanted to add a
third one and a fourth one it gives an error.

In the end i would like to have two buttons that are attached to the macro.
When clicking the button it show different filtered lists

Thanks


--

Dave Peterson
.


--

Dave Peterson
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 to pull data with criterea for placement on a new sheet Trina Excel Discussion (Misc queries) 7 June 13th 08 11:00 PM
Creating a macro to filter data on multiple sheets catfish#hunter Excel Programming 0 May 22nd 08 09:10 PM
how do i countif on multiple criterea? Dan Shoemaker Excel Worksheet Functions 4 May 8th 07 10:31 AM
Macro: Filter Multiple header then extract to Multiple Files [email protected] Excel Discussion (Misc queries) 9 December 8th 06 10:44 PM
Create macro to filter on multiple criteria csdjj021191 Excel Worksheet Functions 7 October 3rd 06 01:52 PM


All times are GMT +1. The time now is 07:19 PM.

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

About Us

"It's about Microsoft Excel"