+ Reply to Thread
Results 1 to 7 of 7

Filter two columns with "or" logic

  1. #1
    Forum Contributor gsnidow's Avatar
    Join Date
    07-22-2010
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    150

    Filter two columns with "or" logic

    Greetings all. I am trying to filter a worksheet where if there is a non-null value in either of two columns, display the entire row. I get complaints from users that the filtering required to come up with different scenarios is too complicated, so I am going to put a series of buttons across the top of the sheet. The below is an example of one where tow columns are both not blank...

    Sub Filter_CXM_Bucket()

    Dim WS As Worksheet
    Set WS = ActiveWorkbook.ActiveSheet

    WS.Select
    'Check to make sure filter is on, in case user took it off
    With Selection
    If Not ActiveSheet.AutoFilterMode Then
    ActiveSheet.Rows("4:4").AutoFilter
    Else
    'If it is on, take it off and put it back to reset
    .AutoFilter
    .AutoFilter
    End If
    'Apply not-blank criteria to columns 21 and 23
    .AutoFilter Field:=21, Criteria1:="<>"
    .AutoFilter Field:=23, Criteria1:="<>", Operator:=xlAnd
    End With

    End Sub

    My thought was I could simply change the 'Operator:=xlAnd' to 'Operator:=xlOr', but it did not work. Is there any way to do this? I am using Excel 2003. Thank you.

    Greg

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Filter two columns with "or" logic

    Hi and welcome to the board


    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  3. #3
    Forum Contributor gsnidow's Avatar
    Join Date
    07-22-2010
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: Filter two columns with "or" logic

    Quote Originally Posted by arthurbr View Post
    Your post does not comply with Rule 3 of our Forum
    I apologize for not properly tagging. Does that mean I should re-post this question?

    Thank you.

  4. #4
    Forum Contributor gsnidow's Avatar
    Join Date
    07-22-2010
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    150

    Re: Filter two columns with "or" logic

    Thank you Andrew. That is what I was thinking. At first I did not like it, but I can't think of a better way.

    Greg

  5. #5
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Filter two columns with "or" logic

    Andrew please do not answer a thread as long as the OP has not complied to a mod's request - Thx

  6. #6
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Filter two columns with "or" logic

    Quote Originally Posted by gsnidow View Post
    I apologize for not properly tagging. Does that mean I should re-post this question?

    Thank you.
    If you click on the word " here" in my post you will find all the explanations needed

  7. #7
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Filter two columns with "or" logic

    Quote Originally Posted by arthurbr View Post
    Andrew please do not answer a thread as long as the OP has not complied to a mod's request - Thx
    Sorry, I'm a newbie. If it makes things better I wasn't very much help.

+ 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