Consulting

Results 1 to 4 of 4

Thread: Filter rows on multiple criteria within a single column

  1. #1
    VBAX Newbie
    Joined
    Nov 2008
    Posts
    2
    Location

    Question Filter rows on multiple criteria within a single column

    Hi,

    I am working on an excel solution where I need to open an excel file with 20 columns and 1000 rows, remove unwanted rows based on multiple criteria. One of the columns (the first one) is "CodeNo" which can have values between 1 and 100. I need to retain the rows with values 10, 20, 40 and 70 and remove the rest of them. I tried to apply the advanced filter (with <>10, <>20, <>40, <>70) but it seems the filter is not being applied cumulatively and I end up with all the rows as they are.

    Please help me solve this. Is there a way to filter cumulatively?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    Add a formula in a helper column of

    =ISNUMBER(MATCH(E2,{10,20,40,70},0))

    assuming E is the code columns, and then filter by that colume with a TRUE value
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    Assuming that your data is layed out such that A1 holds the header "CodeNo":

    If you use a 2 row, 4 column Criteria Range (dots "..." for this display spacing only)

    CodeNo...CodeNo...CodeNo...CodeNo
    <>10......<>20......<>40.....<>70

    AdvancedFilter will show the rows you want to delete.

    Adding rows to a Criteria Range performs a logical OR, adding columns a logical AND.
    (every number is <>10 OR <>20 which is why your 5 row CR acted the way it did.)


    Alernately, a 2 row 1 column CriteriaRange with the top cell empty and the second cell holding the formula =NOT(OR(A2=10,A2=20,A2=40,A2=70))

    will get the same result.

  4. #4
    VBAX Newbie
    Joined
    Nov 2008
    Posts
    2
    Location
    xld and mikerickson, Thank you so much for the prompt replies. I will check both the methods.

Posting Permissions

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