Search code examples
excelvbaadvanced-filter

How to include an "AND" operator and Exclusions in AdvancedFilter with one criteria column in VBA


I am trying to filter a large spreadsheet based on products' item codes.

The file is a print out of product data and a usage statement below it.

The goal is to filter out the usage statements and different products.

Six lines of the column to filter:
enter image description here

I want to only show data for the 5 ...... 58 rows, excluding the 4 ..... 58 and the usages, &X00. &2P2.

I have a criteria range on a different sheet, and input:
enter image description here

It seems the list acts as an "or" operator, it doesn't exclude the 4 NCNDNE 58 row like I would like.

Range(products).AdvancedFilter Action:=xlFilterInPlace, _
     criteriarange:=Worksheets("Criteria").Range(myrange)

Products being the column I'm filtering.
myrange is the array on the other sheet that is being used as a filter.

I did some reading that advancedfilter accepts "<>" as exclusions, but I have not gotten that to work.


Solution

  • To (for example) include all rows which begin with 5 and end with 58 but do not contain FFF your filter range might look like this (side-by-side is AND'ing the criteria) :

    enter image description here

    Related: Exclusion Filtering in Excel Advanced Filter