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
Bookmarks