+ Reply to Thread
Results 1 to 5 of 5

Macro to filter and exclude more than 2 criteria

  1. #1
    Registered User
    Join Date
    05-10-2016
    Location
    UAE
    MS-Off Ver
    2008
    Posts
    6

    Macro to filter and exclude more than 2 criteria

    Hi everyone,

    Im trying to set a filter on multiple columns, see my below code, its working expect the one in red for the filter on column 5, it doesn't give me the correct result. The column 5 is a free text (for the status) field and I want to exclude only the ones that do not contain "Closed", "Credit note" and "Cancelled". These 3 criteria are constant and its much easier to only exclude these as the rest will change everytime

    Please Login or Register  to view this content.
    I also tried with
    Please Login or Register  to view this content.
    It works well but only for 2 criteria, when I added Operator:=x1And, Criteria3:="<>Cancelled" I got an error message.

    Any idea how I can add the 3rd criterion?
    Last edited by alansidman; 10-26-2022 at 04:56 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: Macro to filter and exclude more than 2 criteria

    Please use code tags and not quote tags to show your VBA. Please read the forum rules on how to make this happen. I have made the change for you today.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    05-10-2016
    Location
    UAE
    MS-Off Ver
    2008
    Posts
    6

    Re: Macro to filter and exclude more than 2 criteria

    Anyone able to help please?

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,919

    Re: Macro to filter and exclude more than 2 criteria

    One way is to use a dictionary to get unique values, excluding those three. This leaves the values you want which are then put into an array and passed to the filter.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: Macro to filter and exclude more than 2 criteria

    Any idea how I can add the 3rd criterion?
    Negative filter array is limited to 2 criteria...Can easily achieve...also...via a helper column and filter on this column...
    Will need to see your setup though...The attached will give you an idea...
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 11-08-2022 at 10:44 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] SUMPRODUCT with multiple criteria, how to exclude if does not meet criteria
    By ninja_beth in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-16-2022, 01:14 PM
  2. Next
    By cvici in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2021, 11:20 AM
  3. Replies: 1
    Last Post: 03-25-2020, 08:06 AM
  4. Macro to filter a pivot whilst looping through filter criteria in a variable list.
    By Alistairm88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2015, 04:25 AM
  5. Replies: 3
    Last Post: 04-21-2015, 07:45 AM
  6. [SOLVED] how to exclude a criteria using auto filter
    By kadasanis in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-21-2013, 02:12 PM

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