FilterCopy Unique Values Visible Only

STIguy

New Member
Joined
Nov 5, 2014
Messages
26
Experts,

I would like to be able to filter a list and copy the unique values from a range in another column for the visible cells only. Some digging has provided some examples using xlFilterCopy but I can't seem to get it to work for the visible cells. See the attached data set below.

[TABLE="width: 315"]
<tbody>[TR]
[TD]L1 No.[/TD]
[TD]L2 Item[/TD]
[TD]L2 No.[/TD]
[TD]L3 No.[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]501[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]502[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]503[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]504[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]506[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]601[/TD]
[/TR]
[TR]
[TD]1000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]602[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]501[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]502[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]505[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]601[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]602[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]603[/TD]
[/TR]
[TR]
[TD]2000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]604[/TD]
[/TR]
[TR]
[TD]3000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]501[/TD]
[/TR]
[TR]
[TD]3000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]502[/TD]
[/TR]
[TR]
[TD]3000[/TD]
[TD]1[/TD]
[TD]101[/TD]
[TD]505[/TD]
[/TR]
[TR]
[TD]3000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]601[/TD]
[/TR]
[TR]
[TD]3000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]602[/TD]
[/TR]
[TR]
[TD]3000[/TD]
[TD]2[/TD]
[TD]102[/TD]
[TD]603[/TD]
[/TR]
</tbody>[/TABLE]

In this example I am trying to find the unique L3 No values for each L2 item. If we filter for a value of 1 under L2 item and find the unique values for L3, we are left with the following list:

[TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]501[/TD]
[/TR]
[TR]
[TD="align: right"]502[/TD]
[/TR]
[TR]
[TD="align: right"]503[/TD]
[/TR]
[TR]
[TD="align: right"]504[/TD]
[/TR]
[TR]
[TD="align: right"]505[/TD]
[/TR]
[TR]
[TD="align: right"]506[/TD]
[/TR]
</tbody>[/TABLE]

I would like to be able to copy and paste this list to another worksheet. I am not very familiar with using advanced filters in VBA, but from what I have observed they seem to be very efficient. I did write some similar code to highlight the unique values in a list but it doesnt extract those values. That code is attached below for reference. Thanks!

Code:
Sub HighlightUnique()

    Dim ActSheet As Worksheet
    Dim SelRange As Range


    Set ActSheet = ActiveSheet
    Set SelRange = Selection
    Selection.EntireColumn.FormatConditions.Delete
    With Selection.SpecialCells(xlCellTypeVisible).Select
    
        Selection.FormatConditions.AddUniqueValues
        Selection.FormatConditions(Selection.FormatConditions.count).SetFirstPriority
        Selection.FormatConditions(1).DupeUnique = xlUnique


        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 10284031
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
        
    End With
    
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
@STYguy
And if you use a formula like this will be the some?
Excel Workbook
ABCDE
1No.L2 ItemL2 No.L3 No.unique L3
210001101501501
310001101502502
410001101503503
510001101504504
610001101506506
710002102601601
810002102602602
920001101501505
1020001101502603
1120001101505604
1220002102601
1320002102602
1420002102603
1520002102604
1630001101501
1730001101502
1830001101505
1930002102601
2030002102501
2130002102603
Sheet

let me know!
 
Upvote 0
GerryZ,

Much appreciated! However, i'm trying to add this function to an already existing Sub in VBA so I would like to avoid using embedded spreadsheet formulas.

Is it possible to remove duplicates from a selection (and/or highlight) without removing the original data?

Alex
 
Upvote 0
@STYguy
sorry I forgot the condition
now looks better
let me know if the formula is better!
ciao from italy
Excel Workbook
ABCDE
1No.L2 ItemL2 No.L3 No.unique L3
210001101501501
310001101502601
410001101503602
510001101504603
610001101506604
710002102601
810002102602
920001101501
1020001101502
1120001101505
1220002102601
1320002102602
1420002102603
1520002102604
1630001101501
1730001101502
1830001101505
1930002102601
2030002102501
2130002102603
Sheet
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top