Unique Entries Function

S

samer.kurdi

It seems like it is every couple of weeks that I am searching these
forums for excel tricks and ways to manipulate duplicates in a list.
However, I am wondering if it is possible to put together a simple UDF
that would look like this:


=Uniqueentry(A2:A50000,1) ; where the result would be the FIRST unique
entry in the range.
=Uniqueentry(A2:A50000,2) ; where the result would be the SECOND unique
entry in the range.

and, assuming that the range contains only 100 unique entries:
=Uniqueentry(A2:A50000,101) -- would result in a blank string ("")

Also, I am purposefully using the a2:a50000 example because I need this
UDF to look at huge ranges pretty quickly without calculating for a
long long time.

Any takers out there? I would be forever grateful.
 
R

RB Smissaert

This will do it:

Function UniqueEntry(rngValues As Range, lOrder As Long) As String

Dim i As Long
Dim arr
Dim coll As Collection

Set coll = New Collection

arr = rngValues

For i = 1 To UBound(arr)
On Error Resume Next
coll.Add arr(i, 1), CStr(arr(i, 1))
Next

If lOrder > coll.Count Then
UniqueEntry = ""
Else
UniqueEntry = coll(lOrder)
End If

End Function


Sub test()

MsgBox UniqueEntry(Range(Cells(1), Cells(25, 1)), 2)

End Sub


RBS
 
R

Ron Rosenfeld

It seems like it is every couple of weeks that I am searching these
forums for excel tricks and ways to manipulate duplicates in a list.
However, I am wondering if it is possible to put together a simple UDF
that would look like this:


=Uniqueentry(A2:A50000,1) ; where the result would be the FIRST unique
entry in the range.
=Uniqueentry(A2:A50000,2) ; where the result would be the SECOND unique
entry in the range.

and, assuming that the range contains only 100 unique entries:
=Uniqueentry(A2:A50000,101) -- would result in a blank string ("")

Also, I am purposefully using the a2:a50000 example because I need this
UDF to look at huge ranges pretty quickly without calculating for a
long long time.

Any takers out there? I would be forever grateful.

You could download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr/

Then use this formula:

=INDEX(UNIQUEVALUES(A2:A50000,1),1) for the first
=INDEX(UNIQUEVALUES(A2:A50000,1),2) for the second

These are returned in a sorted order. As written, it will sort ascending. To
sort descending:

=INDEX(UNIQUEVALUES(A2:A50000),1) for the first
=INDEX(UNIQUEVALUES(A2:A50000),2) for the second






--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top