Combine text from multiple cells into one cell if name matches

maggiec27

Board Regular
Joined
Dec 11, 2013
Messages
55
I want to combine the text for any cell in column C if the name in column A matches. Right now I'm using a simple IF/Text Join formula. This won't work for me. =IF(A4=A3,TEXTJOIN(";",TRUE,B3:B5)) It's too simplistic.

I'd really like to look at all of column A and if there are any matches/duplicates, then text join all values in column C for the first match of all matches. If we can flag the other matches so I can quickly delete them or if there is a macro that could do all of this and delete the subsequent matches that would be great. Is this possible?

Name
Product
Products Combined
Maggie Smith
Duffel Bag
Duffel Bag; Protein Shake; Protein Powder
Karen Jones
Vitamins
Joann Bright
Protein Bar
Maggie Smith
Protein Shake
Flag for deletion or automatically delete
Maggie Smith
Protein Powder
Flag for deletion or automatically delete

<tbody>
</tbody>
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
might be easier to:

1. just use a pivot table
2. rebuild the resulting list -- this way you could use a macro to loop through the name column and in a new name column have the name only once with the Products Combine column appending the product every time the name is duplicated.
 
Upvote 0
another option is PowerQuery aka Get&Transform

SourceResult
NameProductNameProduct
Maggie SmithDuffel BagMaggie SmithDuffel Bag, Protein Shake, Protein Powder
Karen JonesVitaminsKaren JonesVitamins
Joann BrightProtein BarJoann BrightProtein Bar
Maggie SmithProtein Shake
Maggie SmithProtein Powder

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Name"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Product", each List.Distinct(Table.Column([Count],"Product"))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Extracted Values" = Table.TransformColumns(#"Removed Columns", {"Product", each Text.Combine(List.Transform(_, Text.From), ", "), type text})
in
    #"Extracted Values"[/SIZE]
 
Upvote 0
another option is PowerQuery aka Get&Transform

SourceResult
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Name[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Product[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Name[/COLOR][COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]Product[/COLOR]
Maggie SmithDuffel BagMaggie SmithDuffel Bag, Protein Shake, Protein Powder
Karen JonesVitaminsKaren JonesVitamins
Joann BrightProtein BarJoann BrightProtein Bar
Maggie SmithProtein Shake
Maggie SmithProtein Powder

<tbody>
</tbody>


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Name"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Product", each List.Distinct(Table.Column([Count],"Product"))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Extracted Values" = Table.TransformColumns(#"Removed Columns", {"Product", each Text.Combine(List.Transform(_, Text.From), ", "), type text})
in
    #"Extracted Values"[/SIZE]



This is amazing! Thank you so much! Works great!!
 
Upvote 0
Is there a way to edit that code to include some manipulation on more columns? There will be other columns, such as Order number, quantity returned
  • Is there a way to somehow update the 'product column' to say 1-protein, 1-duffel bag if the line that is getting merged says 1 for the protein and 1 for the duffel bag?
  • Can we combine the order number separated by semi colons?

Source:
Customer Name
Product
Order Number
Returned Quantity
Maggie Smith
Duffel Bag
1234
1
Karen Jones
Protein Shake
1236
2
Maggie Smith
Protein Bar
1238
2
Maggie Smith
Vitamins
1239
4

<tbody>
</tbody>









Desired:
Customer Name
Product
Order Number
Returned Quantity
Maggie Smith
1-Duffel Bag; 2-Protein Bar; 4-Vitamins
1234;1238;1239
Karen Jones
Protein Shake
1236
2

<tbody>
</tbody>








Is this possible with the Get&Transform tool?
 
Upvote 0
this is a PowerQuery aka Get&Transform :)
Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Customer Name"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Product", each List.Distinct(Table.Column([Count],"Product"))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Order Number", each List.Distinct(Table.Column([Count],"Order Number"))),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Returned Quantity", each List.Distinct(Table.Column([Count],"Returned Quantity"))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Count"}),
    #"Extracted Values" = Table.TransformColumns(#"Removed Columns", {"Product", each Text.Combine(List.Transform(_, Text.From), "; "), type text}),
    #"Extracted Values1" = Table.TransformColumns(#"Extracted Values", {"Order Number", each Text.Combine(List.Transform(_, Text.From), "; "), type text}),
    #"Extracted Values2" = Table.TransformColumns(#"Extracted Values1", {"Returned Quantity", each Text.Combine(List.Transform(_, Text.From), "; "), type text})
in
    #"Extracted Values2"[/SIZE]


Customer NameProductOrder NumberReturned Quantity
Maggie SmithDuffel Bag; Protein Bar; Vitamins1234; 1238; 12391; 2; 4
Karen JonesProtein Shake12362
 
Last edited:
Upvote 0
If you want to SUM of Quantity for Maggie and Karen instead of list

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Customer Name"}, {{"Count", each _, type table}, {"Returned Quantity", each List.Sum([Returned Quantity]), type number}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each List.Distinct(Table.Column([Count],"Product"))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Order Number", each List.Distinct(Table.Column([Count],"Order Number"))),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom1", {"Custom", each Text.Combine(List.Transform(_, Text.From), "; "), type text}),
    #"Extracted Values1" = Table.TransformColumns(#"Extracted Values", {"Order Number", each Text.Combine(List.Transform(_, Text.From), "; "), type text}),
    #"Removed Columns" = Table.RemoveColumns(#"Extracted Values1",{"Count"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Customer Name", "Custom", "Order Number", "Returned Quantity"})
in
    #"Reordered Columns"[/SIZE]


Customer NameCustomOrder NumberReturned Quantity
Maggie SmithDuffel Bag; Protein Bar; Vitamins1234; 1238; 1239
7​
Karen JonesProtein Shake1236
2​
 
Upvote 0
If the number for returned quantity is the same for Maggie, ie: 1,1,1 the end result is giving me just one 1 in the column instead of 3 separated by semicolons.
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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