Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple Criteria Selection with VBA on an Autofilter

Posted on 2010-08-12
3
Medium Priority
?
592 Views
Last Modified: 2012-06-27
I'm sure for anyone with some VBA experience this will be easy as, but for me who has no clue I don't know where to start.

I have a macro pulling data from one sheet with an autofilter on and pasting the data on another:

Range("V3").Select
    ActiveSheet.Range("$A$1:$AG$999").AutoFilter Field:=28, Criteria1:= _
        "Service"
    Range("A1:AG999").Select
    Range("V3").Activate
    Selection.Copy
    Sheets("Email Data").Select
    ActiveSheet.Paste


All i want to do is simply enter another option e.g.

    ActiveSheet.Range("$A$1:$AG$999").AutoFilter Field:=28, Criteria1:= _
        "Service" or "MOT" or "Service And MOT"

but as you will probably notice I have no idea of how to do this. How exactly should i type this into VBA please so it doesn't just pull the "service" data but also the "MOT" and the "Service and MOT"?
0
Comment
Question by:ali_
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 33422212
Are there other values containing Service or MOT other than those three above? You can't have three criteria with AutoFilter so would need a workaround or another method if anwer to previous question was yes. Otherwise, could try

ActiveSheet.Range("$A$1:$AG$999").AutoFilter Field:=28, Criteria1:="=*MOT*", _
        Operator:=xlOr, Criteria2:="=*Service*"
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 33422219
TO clarify, above will return any entry containing MOT or Service.
0
 

Author Closing Comment

by:ali_
ID: 33422656
Spot on. Thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question