Help combining values in excel

tevan

New Member
Joined
Jul 19, 2018
Messages
1
NameItem
Johnapples
Mary oranges
Bobgrapes
Sueoranges
Johnoranges
Johnlemon
Johncelery
Mary grapes
Boboranges
Suecelery
Johnapples,oranges,lemon,celery
Mary oranges,grapes
Bobgrapes,oranges,
Sueoranges,celery

<colgroup><col><col></colgroup><tbody>
</tbody>

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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,215,528
Messages
6,125,342
Members
449,218
Latest member
Excel Master

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