Pull unique values from comma delimited text string into adjacent cell

CF64

Board Regular
Joined
Feb 17, 2021
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hello, Could someone please advise on a formula or macro which could pull out the unique values in a comma delimited cell which may have duplicate text strings into an adjacent cell?

For example in Cell A1 I have:
dog, cat, rabbit, dog, deer, owl, deer, fox, cat, owl

And I would like to put see in cell B1:
dog, cat, rabbit, deer, owl, fox

cell B1 would only pull in cell A1's unique values

Thank you
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
How about
Excel Formula:
=TEXTJOIN(", ",,UNIQUE(TRIM(TEXTSPLIT(A1,,","))))
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
For those not using the 365 version of Excel, here's a UDF that should run in earlier versions.
Book1
AB
1dog, cat, rabbit, dog, deer, owl, deer, fox, cat, owldog, cat, rabbit, deer, owl, fox
Sheet1
Cell Formulas
RangeFormula
B1B1=unqvals(A1)

Function UnqVals(S As String)
Dim V, d As Object
V = Split(S, ", ")
Set d = CreateObject("Scripting.dictionary")
For i = LBound(V) To UBound(V)
If Not d.exists(V(i)) Then d.Add V(i), d.Count + 1
Next i
UnqVals = Join(d.keys, ", ")
End Function
 
Upvote 0
Hi CF64. This split bubble sort seems to work. HTH. Dave
Code:
Sub test()
Dim Splitter As Variant, Splitter2 As Variant
Dim Cnt10 As Integer, Cnt11 As Integer
Splitter = Split(Sheets("Sheet1").Range("A" & 1).Value, ",")
Sheets("Sheet1").Range("B" & 1).Value = Splitter(UBound(Splitter)) & ","
For Cnt10 = UBound(Splitter) To LBound(Splitter) Step -1
Splitter2 = Split(Sheets("Sheet1").Range("B" & 1).Value, ",")
For Cnt11 = UBound(Splitter2) To LBound(Splitter2) Step -1
' more than one entry
If LCase(Splitter(Cnt10)) = LCase(Splitter2(Cnt11)) Then
GoTo bart
End If
Next Cnt11
Sheets("Sheet1").Range("B" & 1).Value = Sheets("Sheet1").Range("B" & 1).Value & Splitter(Cnt10) & ","
bart:
Next Cnt10
Sheets("Sheet1").Range("B" & 1).Value = Left(Sheets("Sheet1").Range("B" & 1).Value, _
                                             Len(Sheets("Sheet1").Range("B" & 1).Value) - 1)

End Sub
Edit: late to the party. Fluff and JoeMo's solution are much more elegant.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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