Print rows as cols without repeats

silversmith

New Member
Joined
Jun 23, 2019
Messages
5
Print rows as cols without repeats

<ins id="aswift_2_expand" data-ad-slot="9830241510" style="text-decoration-line: none; display: inline-table; border: none; height: 250px; margin: 0px; padding: 0px; position: relative; visibility: visible; width: 300px; background-color: transparent;"><ins id="aswift_2_anchor" style="text-decoration-line: none; display: block; border: none; height: 250px; margin: 0px; padding: 0px; position: relative; visibility: visible; width: 300px; background-color: transparent;">******** width="300" height="250" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_2" name="aswift_2" style="left: 0px; position: absolute; top: 0px; border-width: 0px; border-style: initial; width: 300px; height: 250px;">*********></ins></ins>
I have a Excel sheet in which all of a column 1 names may have one to 10 other names in its row.
I want to print out a sheet (Word or Excel) with column 1 name followed by a single column with each of the names in its row .

For example data:

name1 xxx qqq www eee rrr ttt
name2 yyyy aaa bbb
name3 zzz aaa fff eee ggg

desired output:

name1 xxx
------- qqq
------- www
------- eee
------- rrr
------- ttt

name2 yyyy
-------- aaa
-------- bbb

name3 zzz
------- aaa
------- fff
------- eee
------- ggg

(note: dashes are supposed to be empty cell, but this forum editor won't allow spaces)
How do I do this? The number names in a row varies, so regular template won't work. Many Thanks!
Peter​
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
using PowerQuery and PivotTable

Column1Column2Column3Column4Column5Column6Column7Column1Value
name1xxxqqqwwweeerrrtttname1eee
name2yyyyaaabbb qqq
name3zzzaaafffeeegggrrr
ttt
www
xxx
name2aaa
bbb
yyyy
name3aaa
eee
fff
ggg
zzz

Code:
[SIZE=1]// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {"Column1"}, "Attribute", "Value")
in
    Unpivot[/SIZE]

then use PivotTable from external source
 
Upvote 0
Same idea here. Only instead of using a pivot table, I just used conditional formatting to hide the duplicate names.

PQ
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {"Column1"},"Attribute", "Value"),
    Remove = Table.RemoveColumns(Unpivot,{"Attribute"}),
    Rename = Table.RenameColumns(Remove,{{"Column1", "Name"}})
in
    Rename

Conditional Format formula. Select 'Name' column, in this example, from I2:I15, and paste this formula and set font color to white.

Code:
=COUNTIF($I$2:I2,I2)>1
 
Upvote 0
And just for fun, here's a VBA solution as well.

Code:
Sub xPose()
Application.ScreenUpdating = False
Dim AR() As Variant: AR = Range("A1").CurrentRegion
Dim AL As Object: Set AL = CreateObject("System.Collections.ArrayList")

AL.Add ("NAME@VALUE")

For i = LBound(AR) To UBound(AR)
    For j = LBound(AR) + 1 To UBound(AR, 2)
        If AR(i, j) <> vbNullString Then
            If j = 2 Then
                AL.Add AR(i, 1) & "@" & AR(i, j)
            Else
                 AL.Add "@" & AR(i, j)
            End If
        End If
    Next j
Next i

With Range("I1").Resize(AL.Count, 1)
    .Value = Application.Transpose(AL.toArray)
    .TextToColumns DataType:=xlDelimited, OtherChar:="@", FieldInfo:=Array(Array(1, 1), Array(2, 1))
End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you so much for your responses.

For the non VBA methods,(Sandy666, Irobbo314) I really don't know where to put this code to implement. Please guide me.

For the VBA (Irobbo314) when I run this module, I get:

column1column2column3column4column5column6column7NAME@VALUE
name1xxxqqqwwweeerrrtttcolumn1@column2
name2yyyyaaabbb@column3
name3zzzaaafffeeeggg@column4
@column5
@column6
@column7
name1@xxx
@qqq
@www
@eee
@rrr
@ttt
name2@yyyy
@aaa
@bbb
name3@zzz
@aaa
@fff
@eee
@ggg


<tbody>
</tbody>
Obviously my inexperience is showing. Please hand hold me to implement both methods, so I can learn and get the desired output.
Many, Many, Many thanks. Peter
 
Upvote 0
Try this.

Code:
Sub xPose()
Application.ScreenUpdating = False
Dim AR() As Variant: AR = Range("A1").CurrentRegion
Dim AL As Object: Set AL = CreateObject("System.Collections.ArrayList")


AL.Add ("NAME@VALUE")


For i = LBound(AR) To UBound(AR)
    For j = LBound(AR) + 1 To UBound(AR, 2)
        If AR(i, j) <> vbNullString Then
            If j = 2 Then
                AL.Add AR(i, 1) & "@" & AR(i, j)
            Else
                 AL.Add "@" & AR(i, j)
            End If
        End If
    Next j
Next i


With Range("I1").Resize(AL.Count, 1)
    .Value = Application.Transpose(AL.toArray)
    .TextToColumns DataType:=xlDelimited, Other:=True, OtherChar:="@", Tab:=False, Semicolon:=False, Space:=False, Comma:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1))
End With


Application.ScreenUpdating = True
End Sub
 
Upvote 0
This is what I get this time from the code:

name1ValueNAMEVALUE
xxxqqqname1Value
xxxwwwxxxqqq
xxxeeexxxwww
xxxfffxxxeee
xxxtttxxxfff
yyyaaaxxxttt
yyybbbyyyaaa
zzzaaayyybbb
zzzfffzzzaaa
zzzjjjzzzfff
zzzkkkzzzjjj
zzzkkk

<colgroup><col><col><col span="8"></colgroup><tbody>
</tbody>

Maybe we are getting closer? Many thanks.
Peter
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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