We help IT Professionals succeed at work.
Get Started

Excel - Filter Copy/Paste Unique Items

Last Modified: 2017-04-26
I'm trying to perform an AutoFilter on a given set of Data, and with those Visible Rows, copy/paste the unique items from one Column to a Second Column on the same page.

The code would appear to be straightforward:
Sub FilterCopy
Dim wsData As Worksheet, wsLane As Worksheet
Dim DataLR As Long

Set wsLane = Worksheets("LANES")
Set wsData = Worksheets("FMData")

DataLR = wsData.Range("A" & Rows.Count).End(xlUp).Row

wsData.Range("X2:X" & DataLR).ClearContents

   'AutoFilter...Result = Filtered Visible Rows
wsData.Range("A2:H" & DataLR).AutoFilter Field:=2, Criteria1:="=*" & wsLane.[E9] & "*"

   'Copy/Paste Unique Values
wsData.Range("E2:E" & DataLR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsData.Range("X2"), Unique:=True
End Sub

Open in new window

What occurs is the filtered table becomes unfiltered and all unique values from Column E are copied to Column X.  Far more than needed.

How can this best be reliably accomplished so that only the unique values from the Filtered Visible Rows are copy/pasted?

Watch Question
Analyst Assistant
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE