+ Reply to Thread
Results 1 to 3 of 3

Copy unique values from autofilter

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,974

    Copy unique values from autofilter

    On my "View2Pivot" worksheet I have an autofilter applied. I want to copy only the unique, visible items from the second column in my autofilter range. I was hoping this code would do it for me, but I'm getting an error message saying "Object Variable or With Block Variable not set"

    Worksheets("View2Pivot").AutoFilter.Range.Columns(2).AdvancedFilter Action:=xlFilterCopy, _
       CopyToRange:=Wks.Range("F:F"), Unique:=True
    Here's the full macro:
    Sub PertPacsOne()
    Dim Rng As Range
    Dim Wks As Worksheet
    
    Set Wks = Worksheets("Lookups")
    Set Rng = Wks.Range(Wks.Cells(2, "F"), Wks.Cells(Rows.Count, "F").End(xlUp))
    
    Wks.Range("F:F").ClearContents
    Worksheets("View2Pivot").AutoFilter.Range.Columns(2).AdvancedFilter Action:=xlFilterCopy, _
       CopyToRange:=Wks.Range("F:F"), Unique:=True
    
        
        ThisWorkbook.Names.Add "PertPacs1", Rng
        Addx = Range("PertPacs1").Address
    
    End Sub
    Last edited by jomili; 12-07-2010 at 06:39 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,320

    Re: Copy unique values from autofilter

    You can't apply an advanced filter and an autofilter at the same time. You'll have to loop through the visible cells of the relevant column and add them to a collection (or dictionary) to get unique records.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,974

    Re: Copy unique values from autofilter

    I was afraid someone would say that. Oh well, back to the drawing board...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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