Help combining values in excel

tevan

New Member
Joined
Jul 19, 2018
Messages
1
[TABLE="width: 245"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]Name[/TD]
[TD]Item[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]apples[/TD]
[/TR]
[TR]
[TD]Mary [/TD]
[TD]oranges[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]grapes[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD]oranges[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]oranges[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]lemon[/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]celery[/TD]
[/TR]
[TR]
[TD]Mary [/TD]
[TD]grapes[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]oranges[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD]celery[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]John[/TD]
[TD]apples,oranges,lemon,celery[/TD]
[/TR]
[TR]
[TD]Mary [/TD]
[TD]oranges,grapes[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]grapes,oranges,[/TD]
[/TR]
[TR]
[TD]Sue[/TD]
[TD]oranges,celery
[/TD]
[/TR]
</tbody>[/TABLE]

I have a spreadsheet in which I need to combine items listed in several different rows but belong to the same person. Can someone assist in getting on output as I show below? thank you in advance
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
In Excel 2016, you can use TEXTJOIN() to do exactly this. Failing that, the easiest way is with VBA. If you want a formula-only version in a version prior to Excel 2016 then it's not easily done:


Book1
ABCDEF
1NameItemJohnapples,oranges,lemon,celeryapples,oranges,lemon,celery
2JohnapplesMaryoranges,grapesoranges,grapes
3MaryorangesBobgrapes,orangesgrapes,oranges
4BobgrapesSueoranges,celeryoranges,celery
5Sueoranges
6Johnoranges
7Johnlemon
8Johncelery
9Marygrapes
10Boboranges
11Suecelery
Sheet1
Cell Formulas
RangeFormula
F1=ConsolidateList($D1,$A$2:$B$11,1,2)
E1{=TEXTJOIN(",",TRUE,IF($A$2:$A$11=$D1,$B$2:$B$11,""))}
Press CTRL+SHIFT+ENTER to enter array formulas.


Code:
Public Function ConsolidateList(searchTerm As String, sourceRange As Range, searchColumn As Long, resultColumn As Long) As String

Dim i As Long

ConsolidateList = ""

For i = 1 To sourceRange.Rows.Count
    If sourceRange.Cells(i, searchColumn).Value = searchTerm Then ConsolidateList = ConsolidateList & "," & sourceRange.Cells(i, resultColumn).Value
Next i
  
If Len(ConsolidateList) > 1 Then ConsolidateList = Mid(ConsolidateList, 2)

End Function

WBD
 
Upvote 0
This works too:


Excel 2010
AB
1NameItem
2Johnapples
3Maryoranges
4Bobgrapes
5Sueoranges
6Johnoranges
7Johnlemon
8Johncelery
9Marygrapes
10Boboranges
11Suecelery
12
13Johnapples,oranges,lemon,celery
14Maryoranges,grapes
15Bobgrapes,oranges
16Sueoranges,celery
Sheet2
Cell Formulas
RangeFormula
B13=condtextjoin($A$2:$A$11,A13,$B$2:$B$11,",")


Code:
Function condtextjoin(rng As Range, rng2 As Range, rng3 As Range, delimiter As String)
Dim myarray As Variant
myarray = Evaluate("=IF((" & rng.Address & ")=" & rng2.Address & "," & rng3.Address & ")")
condtextjoin = Replace(Replace(Join(Application.Transpose(myarray), delimiter), delimiter & "False", ""), "False" & delimiter, "")
End Function
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
Latest member
laura12345

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