Avatar of Cook09
Cook09
Flag for United States of America asked on

Excel - Filter Copy/Paste Unique Items

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?

Cook09
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Cook09

8/22/2022 - Mon
Norie

I don't think you can apply advanced filter to a column that's already been filtered using autofilter.

What you could do, and I know it's not ideal, is copy the result of the advanced filter to another (temporary) sheet and then do the advanced filter on that sheet returning the results to the original sheet.

Would that be of any use?
Cook09

ASKER
Norie,

Possibly...I have Columns A-H which will be filtered...I can then Copy those visible rows to L-S...and then copy/paste the Unique values to Column X.  Is that what your referring too?  How would that code sequence work?

Cook09
Cook09

ASKER
You pointed me in the right direction...just did multiple filters, and copied to static range and extracted unique from that one.  

What I noticed though is to fully  clear a double filter, the "ShowAllData" needs to be run twice.  Is that normal?

Another quick question: Since the Extracted Unique Data was going into a combobox, how does one have the first value show up in the combobox as the first selection, instead of seeing a blank and then having to select the down arrow to view the different options.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Norie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Cook09

ASKER
Thanks for the guidance..

Cook09