I am trying to filter data by named range critera. For instance, in column B, cells fall into various named ranges (B2, B10, and B12 belong to named range "FirstNamedRange"; B4, B10, and B8 belong to "SecondNamedRange"; and B22, B23, and B25 belong to "ThirdNamedRange"). As you can see from these examples, not all cells in column B are assigned to a particular named range, and cell B10 belongs to both FirstNamed Range and SecondNamedRange.
I want to filter by a specified named ranges but cannot figure out how to indicate a named range as the criteria. Below are some codes that I have tried with no success - mismatch errors, no critera pulled, etc. To give you a general idea of my plans for this piece of code, I am going to use it to filter and show all cells belonging to FirstNamedRange and then I will use it to build a code to filter and show all cells belonging to FirstNamedRange OR SecondNamedRange, then FirstNamedRange AND SecondNamedRange....That kind of idea.
Dim rData As Range, rCrit As Range
Set rData = Intersect(Sheet2.UsedRange, Range("B:B"))
Set rCrit = Sheet2.Range("FirstNamedRange")
rData.AdvancedFilter xlFilterInPlace, rCrit
Dim FirstNamedRange As String
Sheet2.Range("A1:Z1").AutoFilter Field:=2, Criteria1:=CLng(Sheet2.Range("FirstNamedRange"))
Thank you in advance for any help you can provide. Any forum threads I have found on the internet on this subject have proven unhelpful.
Bookmarks