Consulting

Results 1 to 6 of 6

Thread: Autofilter problem

  1. #1
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    3
    Location

    Question Autofilter problem

    I am using the following code to find PTS in column 2 and 3, the problem is it is only finding PTS if it appears in column 2 & 3 on the same row else you do not see them if PTS is just in column 2 or column 3.



    ActiveSheet.Range("$A$6:$IP$340").AutoFilter Field:=2, Criteria1:= _
            "=PTS*", Operator:=xlOr
        ActiveSheet.Range("$A$6:$IP$340").AutoFilter Field:=3, Criteria1:= _
            "=PTS*", Operator:=xlOr

    Is there a simple fix some one can provide that will display all rows containing PTS whether it is in column 2 or column 3 else i am having to run 2 seperate filters


    Many thanks in advance

    Mark

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Mark
    You can't Autofilter xlOr on two columns, You can either use advance filter or add a helper column combining the data from Columns 2 & 3 then filter for "=*PTS*"
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    3
    Location
    Many thanks

    Is there code to do this i.e. amend this code:
    ActiveSheet.Range("$A$6:$IP$340").AutoFilter Field:=2, Criteria1:= _
    "=PTS*", Operator:=xlOr
    ActiveSheet.Range("$A$6:$IP$340").AutoFilter Field:=3, Criteria1:= _
    "=PTS*", Operator:=xlOr


    Or will i need to actually go through the process of using the advanced filter?



  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Is there code to do this i.e. amend this code
    You can't amend that code, but this will add and filter on a helper column

    Sub Test()
    With ActiveSheet
    For Each cel In .Range("IQ6:IQ340")
        cel.Value = cel.Offset(, -249) & cel.Offset(, -248)
    Next
    .Range("$IQ$6:$IQ$340").AutoFilter Field:=1, Criteria1:="=*PTS*"
    End With
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    3
    Location
    cheers

    I was hoping to avoid the 'helper' column option, i will have a go at the advanced filter.
    Many thanks for your help

    M

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    Quote Originally Posted by M8rix View Post
    i will have a go at the advanced filter.
    See attached.

    (Instead of the formula:
    ="=PTS*"
    you could have:
    '=PTS*
    or, as it turns out, just:
    PTS
    in the advanced criteria cells.)
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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