+ Reply to Thread
Results 1 to 13 of 13

VBA Filter Using Named Ranges as Criteria

Hybrid View

  1. #1
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: VBA Filter Using Named Ranges as Criteria

    I don't think you can't use a non-contigous range to filter by, all your ranges are non-contiguous.

    Also, none of them include the header.

    Perhaps you should copy the criteria to another range and then filter by that.
    Dim rData As Range, rCrit As Range
        Set rData = Intersect(Sheet1.UsedRange, Range("B:B"))
        Set rCrit = Sheet1.Range("FirstNamedRange")
     
        rCrit.Copy
        With Range("L1")
            .Value = Range("B1").Value
            .Offset(1).PasteSpecial xlPasteAll, SkipBlanks:=True
            Set rCrit = .Item(1).Resize(rCrit.Cells.Count + 1)
        End With
        
        rData.AdvancedFilter xlFilterInPlace, rCrit
    If posting code please use code tags, see here.

  2. #2
    Registered User
    Join Date
    02-11-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA Filter Using Named Ranges as Criteria

    Wonderful! It worked really well. Would you mind explaining to me what the following is doing/describing: ".Item(1).Resize(rCrit.Cells.Count + 1)"

    And one more question, which range is "UsedRange" referring to? Is it considering L2 through L4 to be the last used range?

    Thank you both very much for all your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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