+ Reply to Thread
Results 1 to 3 of 3

Autofilter for more than 2 criteria in one column using VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    12-20-2005
    Posts
    44

    Autofilter for more than 2 criteria in one column using VBA

    I am trying to use VBA to filter a column for more than 2 criteria.

    I am using Excel 2003 currently.

    I know you can work around the 3 condition max rule in conditional formatting with VBA code, but can you do similar with Autofilter?

    e.g.

    This works for 2 criteria:

    Selection.AutoFilter Field:=9, Criteria1:="<>*SHOP*", Operator:=xlAnd, Criteria2:="<>*STOCK*"
    I tried to add another:

    Selection.AutoFilter Field:=9, Criteria1:="<>*SHOP*", Operator:=xlAnd, Criteria2:="<>*STOCK*", Criteria3:="<>*TOOL*"
    and I get Runtime Error: 1004, application-defined or object-defined error.

    I also know that I can create a helper column with a formula and filter by that... but wondering if there is a VBA trick out there.

    Thanks.
    Last edited by JohnnyBGood; 08-23-2011 at 11:19 AM.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Autofilter for more than 2 criteria in one column using VBA

    Hi,

    In XL2003 you are restricted to 2 criteria. Like you say, you could create a helper column. Alternatively, you could use the Advanced Filter (which would require a criteria range).
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    12-20-2005
    Posts
    44

    Re: Autofilter for more than 2 criteria in one column using VBA

    Thanks Colin,

    I managed it with Advance Filter as you suggested.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1