VBA Autofilter rows where value in column are NOT in a list

Pigankle

New Member
Joined
Apr 18, 2011
Messages
32
I am trying to set up a routine to filter moderately large data sets. Think of it like daily rainfall for 60 years. I can get the data into a sheet where each row represents one year's worth of data, with the years entered in column 4.

One possible filter is to exclude everything outside of a certain range of years/totalrainfalls/percentileranks:

Code:
With rRange 'Filter, offset(to exclude headers) and delete visible rows
      .AutoFilter Field:=lCol, Criteria1:="<" & minCrit, _
      Operator:=xlOr, Criteria2:=">" & maxCrit
      .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End With

I give this a column containing the criterion (lCol) I care about and the max and min for that test and it works fine.

I would also like to be able to filter out years not on a user supplied list.


Code:
 With rRange 'Filter, offset(to exclude headers) and delete visible rows
      .AutoFilter Field:=lCol, Criteria1:="<>" & yearArray, _
      Operator:=xlFilterValues
            .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End With

I am picking up this project after leaving it alone for a month, and I don't remember why I ever thought this code would work, but it doesn't, and I don't know how to proceed. I need an autofilter command or subroutine that will hide rows if the value in a particular column matches ANY of the values on a list.

Any suggestions?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top