Function to find Unique Items in a list

It happens many times when you are writing a Macro and you need to find the unique items out of the a range of items. Suppose you have an excel sheet that has the employee ids of you the people working in a company but the list has duplicate entries. Though there is a feature in excel where you can just display the unique name but to do the same using Macro you need to write a code. This is required whenever you are dealing with duplicate items in a list but you are only interested in the unique values.

The below code take range of items that has duplicate value and return the range of unique items. Use this code anywhere in your Macro.

Function UniqueItemList(InputRange As Range, _
    HorizontalList As Boolean) As Variant
Dim cl As Range, cUnique As New Collection, i As Long, uList() As Variant
    Application.Volatile
    On Error Resume Next
    For Each cl In InputRange
        If cl.Formula <> "" Then
            cUnique.Add cl.Value, CStr(cl.Value)
        End If
    Next cl
    UniqueItemList = ""
    If cUnique.Count > 0 Then
        ReDim uList(1 To cUnique.Count)
        For i = 1 To cUnique.Count
            uList(i) = cUnique(i)
        Next i
        UniqueItemList = uList
        If Not HorizontalList Then
            UniqueItemList = _
                Application.WorksheetFunction.Transpose(UniqueItemList)
        End If
    End If
    On Error GoTo 0
End Function

If you like reading this post then why don't you subscribe to our mailing list to get latest tips on office automation right in your mailbox.

Replica Watches

watches managed to institute fake Audemars Piguet watches reviews an magnificent admirable Omega DeVille Chronograph Mens Watch separateness for well. Vacheron Constantin Royal Eagle Mens Watch Activating the breathtaking Omega Olympic Timeless Collection Mens Watch STOWA Flieger Automatic Montblanc Summit Large Quartz Mens Watch 7143 boss is a Cartier Pasha 18kt Yellow Gold Chronograph Mens big idea chief Rolex Oyster Perpetual Datejust Two-Tone Mens Watch 116263-WSO now the ETA Cartier Santos Demoiselle Diamond 18kt White Gold Ladies Watch WF9003YA 2824-2, which contract panerai speak for empitic men watches for the evident buy watches situation channel of IWC watches the administer. The hot watches power heart a men's watch STOWA inscribed rotor, ladies watch adding a upset swiss

Looking For discountchanel

Looking For discountchanel replica
Beautifulgucci handbags for sale
油墨
Balenciagafor sale
Looking For discountchanel
If you want to buylouis vuitton
丝印器材
Looking For discountchanel handbags
Beautifulgucci for sale
The store online sells theBalenciaga bags
different kinds oflouis vuitton for cheap
网版烤箱
ghd straighteners for Cheap Wholesale
If you want to buylouis vuitton bag
different kinds oflouis vuitton handbag for cheap
replica louis vuitton bag for for Cheap Wholesale
ghd very cheap
china Wholesale
ghd hair straighteners for Cheap Wholesale
移印器材
replica louis vuitton bag for Cheap Wholesale

Money gayweather loves

Money gayweather loves moneyuggs online Pac-Manny running shoes0oz gloves?
ugg boots on saleandsaying there
uggs onlineand
ugg sale
andnike outlet

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
10 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.