Unique values from column where cells have multiple values with a delimiter

ausswe

New Member
Joined
Feb 19, 2013
Messages
35
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,
I've been sourcing around to figure out how to use a formula to get a unique list with values in a column where some cells have multiple values in the same cell with "; " as a delimiter between them. Would anyone have any ideas?

Example:

A (unique values from B)B
Sarskild boendeformSarskild boendeform; Trygghetslarm; Boendestod; Matdistribution
TrygghetslarmMatdistribution
BoendestodSarskild boendeform; Trygghetslarm; Matdistribution
MatdistributionTrygghetslarm
Boendestod; Matdistribution
Sarskild boendeform
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
the spreadsheet contains approx. 5600 rows.
Perhaps then you could consider a user-defined function like this? (It will not work on your MacOS platform though, only Windows)

VBA Code:
Function UniqueList(rng As Range, Optional Delim As String = ";") As Variant
  Dim d As Object
  Dim a As Variant, itm As Variant
  Dim i As Long
 
  a = rng.Value
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  For i = 1 To UBound(a)
    For Each itm In Split(a(i, 1), Delim)
      d(LTrim(itm)) = 1
    Next itm
  Next i
  UniqueList = Application.Transpose(d.keys)
End Function

ausswe.xlsm
AB
1A (unique values from B)B
2Sarskild boendeformSarskild boendeform; Trygghetslarm; Boendestod; Matdistribution
3TrygghetslarmMatdistribution
4BoendestodSarskild boendeform; Trygghetslarm; Matdistribution
5MatdistributionTrygghetslarm
6Boendestod; Matdistribution
7Sarskild boendeform
Sheet3
Cell Formulas
RangeFormula
A2:A5A2=UniqueList(B2:B7)
Dynamic array formulas.


Note that the function has an option to use a different delimiter so it could be used like this as well

ausswe.xlsm
AB
1A (unique values from B)B
2Sarskild boendeformSarskild boendeform|Trygghetslarm|Boendestod|Matdistribution
3TrygghetslarmMatdistribution
4BoendestodSarskild boendeform|Trygghetslarm|Matdistribution
5MatdistributionTrygghetslarm
6Boendestod|Matdistribution
7Sarskild boendeform
Sheet4
Cell Formulas
RangeFormula
A2:A5A2=UniqueList(B2:B7,"|")
Dynamic array formulas.
 
Upvote 1
Thanks Peter, I did some testing and it seems like the earlier formula from @ReeceBmp is working
(=UNIQUE(FILTERXML("<root><s>"&SUBSTITUTE(A:A,"; ","</s><s>")&"</s></root>","//s")).
The #VALUE! error seems to come from the fact that some of the cells are empty and as such returning the error message.
 
Upvote 0
I did some testing and it seems like the earlier formula from @ReeceBmp is working
@Fluff stated earlier
It might appear to work, but it doesn't. It will only return the 1st word from each cell.

I agree with Fluff, it only returns a unique list of first words from the cells. That is not what you asked for.
Here is a small example with that formula (& it did take a few minutes to calculate!)
For this sample, didn't you want the formula to also return "def" and "ghi" etc?

ausswe.xlsm
AB
1abc; def; ghi; jklabc
2mno; pqr; stumno
3vwx; yza; bcd; efgvwx
4abc; jkl#VALUE!
5
Sheet
Cell Formulas
RangeFormula
B1:B4B1=UNIQUE(FILTERXML("<root><s>"&SUBSTITUTE(A:A,"; ","</s><s>")&"</s></root>","//s"))
Dynamic array formulas.
 
Upvote 0
Another formula option
Excel Formula:
=UNIQUE(DROP(REDUCE("",B2:B6000,LAMBDA(x,y,IF(y="",x,VSTACK(x,TEXTSPLIT(y,,"; "))))),1))
 
Upvote 0
Another formula option
Excel Formula:
=UNIQUE(DROP(REDUCE("",B2:B6000,LAMBDA(x,y,IF(y="",x,VSTACK(x,TEXTSPLIT(y,,"; "))))),1))
The same post I got the formula above from indicated that the use of Lamda made the performance quite slow.
I tried your formula and that seems to be the case. The other formula is almost instant.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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