Unique Values from a single cell

pmurugan

New Member
Joined
Dec 18, 2013
Messages
2
Hi,

I have a single cell comprising A|B|C| A. How do i get the unique values? Also please let me know if there is a chance to count the variables.

Thanks. I badly need a excel function to sort this out.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try these functions, which can be called from VBA or as user-defined functions in a cell.

Code:
Public Function UniqueVar(cellValue As String) As String
    
    Static dict As Object
    Dim items As Variant, item As Variant
    Dim key As Variant
    
    items = Split(cellValue, "|")
    
    If dict Is Nothing Then Set dict = CreateObject("Scripting.Dictionary")

    For Each item In items
        dict(item) = item
    Next
    
    UniqueVar = ""
    For Each key In dict.Keys()
        UniqueVar = UniqueVar & key & " "
    Next
    
    dict.RemoveAll
    
    UniqueVar = Left(UniqueVar, Len(UniqueVar) - 1) + 1
    
End Function


Public Function CountVar(cellValue As String) As Integer
    
    Dim items As Variant
    
    items = Split(cellValue, "|")
    CountVar = UBound(items) - LBound(items)
    
End Function
I'm not sure whether the count you want is the count of all the values or just the unique values. CountVar() counts the former. If you want the latter then use similar code as UniqueVar(), and return dict.count.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,937
Latest member
BeerMan23

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