Convert 1 label, 1 entry per row table to 1 label, multiple entries per row table

Hawkser

New Member
Joined
Nov 30, 2018
Messages
1
I have a very basic table (two columns) with thousands of rows. Column A has a label, and column B has an entry. There can be multiple entries (rows) per label, but the number of entries per label will vary.

(original table)
Label A, Entry 1
Label A, Entry 2
Label B, Entry 1
Label C, Entry 1
Label C, Entry 2
Label C, Entry 3
...

If I convert that to a Pivot Table, it is very easy to produce ...

Label A
Entry 1
Entry 2
Label B
Entry 1
Label C
Entry 1
Entry 2
Entry 3

What I need, is the following output ...

Label A, Entry 1, Entry 2
Label B, Entry 1
Label C, Entry 1, Entry 2, Entry 3


Basically, I need a table that is one label per row, followed by however many entries there are for that label.

I am struggling to understand how to get from the original table to the desired output. The pivot table is close to what I need, I just need the entries to be listed horizontally across multiple columns, instead of listed down multiple rows. But those groupings of entries per label is exactly what I need, just a different format. Maybe I need to use VBA and some scripting? Or maybe there is a function built into Excel already to simply produce the desired output? Any ideas or guidance would be appreciated.

TIA.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Maybe this

Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = lr To 2 Step -1
    If Range("A" & r).Value = Range("A" & r - 1).Value Then
        Range("B" & r - 1).Value = Range("B" & r - 1).Value & ", " & Range("B" & r).Value
        Rows(r).Delete
    End If
Next r
End Sub
 
Upvote 0
or with PowerQuery (Get&Transform)

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

LabelEntryLabelEntry
Label A Entry 1Label A Entry 1, Entry 2
Label A Entry 2Label B Entry 1
Label B Entry 1Label C Entry 1, Entry 2, Entry 3
Label C Entry 1
Label C Entry 2
Label C Entry 3
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,803
Members
449,127
Latest member
Cyko

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