How to concatenate list entries with the same ID into one cell?

ganguro

New Member
Joined
Jun 18, 2014
Messages
3
Hi excel family!

need your help.

this is the situation I face in Excel:

Cell A is a non-unique key field.
Cell B is the assigned value.

Cell A_______Cell B
AAA_________TMPL
AAA_________TMPS
AAA_________TMPO
BBB_________TMPS
CCC_________TMPS
CCC_________TMPO
DDD_________TMPL
DDD_________TMPS
DDD_________TMPO
DDD_________TMPX
EEE__________TMPL
EEE__________TMPS


This is what I want to achieve:


Cell A_______Cell B
AAA_________TMPL + TMPS + TMPO
BBB_________TMPS
CCC_________TMPS + TMPO
DDD_________TMPL + TMPS + TMPO
EEE__________TMPL + TMPS

I want to concatenate the list entries into one cell and separate them with a + or an & sign.

How can I achieve this?

Thx a lot in advance!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Suppose you have headers in A1:B1
Try this code
VBA Code:
Sub Demo()
    Dim a, d As Object, i As Long

    With ActiveSheet
        a = .Range("A2:B" & .Cells(Rows.Count, 1).End(xlUp).Row).Value
        Set d = CreateObject("Scripting.Dictionary")

        For i = LBound(a) To UBound(a)
            If Not d.Exists(a(i, 1)) Then d(a(i, 1)) = a(i, 2) Else d(a(i, 1)) = d(a(i, 1)) & " + " & a(i, 2)
        Next i
   
        With .Range("E1")
            .Resize(1, 2).Value = Array("Header1", "Header2")
            .Offset(1).Resize(d.Count).Value = Application.Transpose(d.Keys)
            .Offset(1, 1).Resize(d.Count).Value = Application.Transpose(d.Items)
        End With
    End With
End Sub
 
Upvote 0
another way with Power Query (Get&Transform)

Cell ACell BCell AList
AAATMPLAAATMPL & TMPS & TMPO
AAATMPSBBBTMPS
AAATMPOCCCTMPS & TMPO
BBBTMPSDDDTMPL & TMPS & TMPO & TMPX
CCCTMPSEEETMPL & TMPS
CCCTMPO
DDDTMPL
DDDTMPS
DDDTMPO
DDDTMPX
EEETMPL
EEETMPS


Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    List = Table.AddColumn(Table.Group(Source, {"Cell A"}, {{"Count", each _, type table}}), "List", each Table.Column([Count],"Cell B")),
    Extract = Table.TransformColumns(List, {"List", each Text.Combine(List.Transform(_, Text.From), " & "), type text})
in
    Extract
 
Upvote 0
.. or a worksheet formula approach (if you have the TEXTJOIN function)
D2 copied down as far as you might ever need.
E2 is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down as far as D2 was.

Book1
ABCDE
1KeyValueKeyValues
2AAATMPLAAATMPL + TMPS + TMPO
3AAATMPSBBBTMPS
4AAATMPOCCCTMPS + TMPO
5BBBTMPSDDDTMPL + TMPS + TMPO + TMPX
6CCCTMPSEEETMPL + TMPS
7CCCTMPO  
8DDDTMPL  
9DDDTMPS  
10DDDTMPO  
11DDDTMPX
12EEETMPL
13EEETMPS
14
Concat
Cell Formulas
RangeFormula
D2:D10D2=IFERROR(INDEX($A$2:$A$20,MATCH(0,INDEX(COUNTIF($D$1:D1,$A$2:$A$20)+(A$2:A$20=""),0),0)),"")
E2:E10E2{=IF(D2="","",TEXTJOIN(" + ",1,IF(A$2:A$20=D2,B$2:B$20,"")))}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,796
Members
448,994
Latest member
rohitsomani

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