Consulting

Results 1 to 6 of 6

Thread: Solved: Autofilter for multiple condition

  1. #1
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location

    Solved: Autofilter for multiple condition

    Hi, I need help with filtering column with followiing conditions. I received following code from recording macro but this somehow doesn't seem to be right. Please note that my table heading is located at Row 5.

    1) From Column I, select "In-service" AND "Temporarily Out of Service"
    2) From Column H, select "*U/G"
    3) From Column M, select "FRP"
    4) From Column Q, select "None" AND "vaule w/access"

    Recording the macro doesn't seem to be right for item 2) and 4). Can someone please edit the code? Thanks.


    [VBA]Sub SWFRPUSTs()
    Selection.AutoFilter Field:=7, Criteria1:="=1. In-Service", Operator:= _
    xlAnd
    Selection.AutoFilter Field:=6, Criteria1:="=*U/G*", Operator:=xlAnd
    Selection.AutoFilter Field:=11, Criteria1:="6. FRP"
    Selection.AutoFilter Field:=15, Criteria1:="=0. None", Operator:=xlAnd

    End Sub[/VBA]
    -u

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This seems to work

    [VBA]

    With Selection

    .AutoFilter Field:=6, Criteria1:="=*U/G*", Operator:=xlAnd
    .AutoFilter Field:=7, Criteria1:="=1. In-Service", _
    Operator:=xlOr, _
    Criteria2:="=2. cc"
    .AutoFilter Field:=11, Criteria1:="=6. FRP", Operator:=xlAnd
    .AutoFilter Field:=15, Criteria1:="=None", Operator:=xlAnd
    End With
    [/VBA]
    ____________________________________________
    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
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    pl. ignore this! and check the next one.
    -u

  4. #4
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    2-questions.
    i) From Column I, select "In-service" AND "Temporarily Out of Service": To select these 2-criteria from column I, should I put the line in code as follows?
    [vba]AutoFilter Field:=7, Criteria1:="=1. In-Service", _
    Operator:=xlOr, _
    Criteria2:="=2. Temporarily Out of Service" [/vba]
    ii) What does "Field 7" mean? Is it signifying Column I?
    Thanks.
    -u

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    i) Yes that is correct

    ii) Field refers to the column within the autofiltered columns. From you original code I deduced that you had an autofilter on all columns C:Q (at least). column I is the 7th column within this column set (C is1, D is 2, E is 3, etc.).
    ____________________________________________
    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

  6. #6
    VBAX Tutor
    Joined
    Feb 2008
    Location
    New York
    Posts
    215
    Location
    hi xld,

    thank you very much for the code and the explanation. it works for me. your help is very much appreciated
    -u

Posting Permissions

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