Excel Formula to Transpose Comma Separated Cells into One Column

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I was looking for a formula that would give me a unique column of comma separated cells: Please see below. Thanks in advance!!!

Book4
ABCDE
1NamesDon
2Don, Jake, Mike, Jeff, BrianJake
3Jake, Dianny, Sandra, Brian, Mark, JeffMike
4Sally, Don, Ben, Ken, Jeff, BrianJeff
5Ray, Ted, Jake, MarkBrian
6Dianny
7Sandra
8Mark
9Sally
10Ben
11Ken
12Ray
13Ted
Sheet1
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
NamesNames
Don, Jake, Mike, Jeff, BrianDon
Jake, Dianny, Sandra, Brian, Mark, JeffJake
Sally, Don, Ben, Ken, Jeff, BrianMike
Ray, Ted, Jake, MarkJeff
Brian
Dianny
Sandra
Mark
Sally
Ben
Ken
Ray
Ted

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Split = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Names", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Names"),
    Distinct = Table.Distinct(Table.TransformColumns(Split,{{"Names", Text.Trim, type text}}))
in
    Distinct
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
If you have the LET function, how about
+Fluff 1.xlsm
ABC
1Names
2Don, Jake, Mike, Jeff, BrianDon
3Jake, Dianny, Sandra, Brian, Mark, JeffJake
4Sally, Don, Ben, Ken, Jeff, BrianMike
5Ray, Ted, Jake, MarkJeff
6Brian
7Dianny
8Sandra
9Mark
10Sally
11Ben
12Ken
13Ray
14Ted
15
Main
Cell Formulas
RangeFormula
C2:C14C2=LET(Ary,TRIM(MID(SUBSTITUTE(A2:A5,",",REPT(" ",100)),SEQUENCE(,5,,100),100)),Cols,COLUMNS(Ary),Seq,SEQUENCE(ROWS(Ary)*Cols,,0),Indx,INDEX(Ary,Seq/Cols+1,MOD(Seq,Cols)+1),UNIQUE(FILTER(Indx,Indx<>"")))
Dynamic array formulas.
 
Upvote 0
Solution
Ahh!!! I do have Let! Thank you both for your help!! I appreciate both techniques to solve the issue!!!
 
Upvote 0
I appreciate both techniques to solve the issue!!!
Are you sure that formula as-is solves the issue?

I believe that formula will only work reliably for up to 5 names per cell. Although it worked for your sample and there are 6 names in A3 & A4 it was just lucky that the 6th names, Jeff & Brian, appeared elsewhere as well. Try changing that Jeff in A3 to Jeffrey or add "Ann" to A3 as well.

This could be (partially) overcome by increasing the SEQUENCE value to something greater than the maximum expected number of names in a single cells. eg
=LET(Ary,TRIM(MID(SUBSTITUTE(A2:A5,",",REPT(" ",100)),SEQUENCE(,20,,100),100)),Cols,COLUMNS(Ary),Seq,SEQUENCE(ROWS(Ary)*Cols,,0),Indx,INDEX(Ary,Seq/Cols+1,MOD(Seq,Cols)+1),UNIQUE(FILTER(Indx,Indx<>"")))

However, if the length of the text in a single cell could be reasonably large, then errors could also occur due to the use of 100 spaces in the formula to separate the names. Here is an example where I have used 20 as shown above but with only 11 names in one cell the results are not correct.

21 02 01.xlsm
ABC
1Names
2FirstName1, FirstName2, FirstName3, FirstName4, FirstName5, FirstName6, FirstName7, FirstName8, FirstName9, FirstName10, FirstName11FirstName1
3Jake, Dianny, Sandra, Brian, Mark, JeffFirstName2
4FirstName3
5FirstName4
6FirstName5
7FirstName6
8FirstName7
9FirstName8
10FirstName9
11F
12irstName10
13FirstName11
14Jake
15Dianny
16Sandra
17Brian
18Mark
19Jeff
20
List
Cell Formulas
RangeFormula
C2:C19C2=LET(Ary,TRIM(MID(SUBSTITUTE(A2:A5,",",REPT(" ",100)),SEQUENCE(,50,,100),100)),Cols,COLUMNS(Ary),Seq,SEQUENCE(ROWS(Ary)*Cols,,0),Indx,INDEX(Ary,Seq/Cols+1,MOD(Seq,Cols)+1),UNIQUE(FILTER(Indx,Indx<>"")))
Dynamic array formulas.


This second issue could also be improved by increasing the 100 values.
However, here is an alternative formula that overcomes both the issues above, but may introduce another one - mentioned below.

21 02 01.xlsm
ABC
1Names
2Don, Jake, Mike, Jeff, BrianDon
3Jake, Dianny, Sandra, Brian, Mark, JeffJake
4Sally, Don, Ben, Ken, Jeff, BrianMike
5Ray, Ted, Jake, MarkJeff
6Brian
7Dianny
8Sandra
9Mark
10Sally
11Ben
12Ken
13Ray
14Ted
15
List (2)
Cell Formulas
RangeFormula
C2:C14C2=LET(s,","&TEXTJOIN(",",1,SUBSTITUTE(A2:A5,", ",","))&",",q,SEQUENCE((LEN(s)-LEN(SUBSTITUTE(s,",","")))-1), UNIQUE(REPLACE(LEFT(s,FIND("|",SUBSTITUTE(s,",","|",q+1))-1),1,FIND("|",SUBSTITUTE(s,",","|",q)),"")))
Dynamic array formulas.


The possible issue with my formula is if the list of all the names in column A, joined by commas, was longer than 32,767 characters. In that case TEXTJOIN would throw an error & the formula would not work.

So a few things for you to consider at least. :)
 
Upvote 0
Thanks Peter_SSs for being thorough. I was going to try it today on a larger data set. I appreciate you looking over the formula and guiding me to the potential issues. Always appreciate any help that I can get. Thank you very much!
 
Upvote 0
Thanks Peter_SSs for being thorough. I was going to try it today on a larger data set. I appreciate you looking over the formula and guiding me to the potential issues. Always appreciate any help that I can get. Thank you very much!
You're welcome. Glad to contribute. :)
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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