FindUniqueValues Issue

GonzoB

New Member
Joined
Dec 4, 2021
Messages
43
Hi Helpers,

I have an issue with function FindUniqueValues. When I'm running it in my target field I can always find one value appearing twice. This is 17583 (row 2 and 4). Can somebody help to understand why this is happening and how to resolve?

Source table:
ZTT Roster-vlookup-data.xlsm
ABCDE
1column Acolumn Bcolumn Ccolumn Dcolumn E
2xyz17583xyzxyzxyz
3xyz17839xyzxyzxyz
4xyz17583xyzxyzxyz
5xyz17583xyzxyzxyz
6xyz17583xyzxyzxyz
7xyz17839xyzxyzxyz
8xyz17839xyzxyzxyz
9xyz17839xyzxyzxyz
10xyz18924xyzxyzxyz
11xyz19080xyzxyzxyz
12xyz19088xyzxyzxyz
13xyz19089xyzxyzxyz
14xyz19542xyzxyzxyz
15xyz17611xyzxyzxyz
Export


Target Sheet:
ZTT Roster-vlookup-data.xlsm
ABCD
1column B
217583
317839
417583
518924
619080
719088
819089
919542
1017611
1117622
1217699
1317312
1417313
1517314
1617317
ZTT


VBA:

VBA Code:
Sub create_Results_sheet()


Dim ws1 As Worksheet
Dim sheet_name As String

sheet_name = "Results"

With ThisWorkbook
    Set ws1 = .Sheets.Add(After:=.Sheets(.Sheets.Count))
    ws1.Name = sheet_name
    
    Cells(1, 2).Value2 = "column B"

End With


Dim ExportRow As Long
ExportRow = Worksheets("Export").Cells(Rows.Count, 1).End(xlUp).Row


FindUniqueValues Worksheets("Export").Range("B2:B" & ExportRow), Worksheets(sheet_name).Range("B2")


End Sub

Sub FindUniqueValues(SourceRange As Range, TargetCell As Range)

SourceRange.AdvancedFilter Action:=xlFilterCopy, _
        CopyToRange:=TargetCell, Unique:=True
        
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try
VBA Code:
FindUniqueValues Worksheets("Export").Range("B1:B" & ExportRow), Worksheets(sheet_name).Range("B2")
Otherwise B2 is being treated as a header, rather than a value.
 
Upvote 0
Solution
Thanks Fluff.

What I also realized is that there's no way to exclude the header from the listing of the distinct values. Therefore I'm using now a Delete Row command at the end of the script to remove the header value from my target sheet.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,168
Members
449,296
Latest member
tinneytwin

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