"Collapse" Matrix?

dunnma

New Member
Joined
Dec 7, 2017
Messages
2
Given the following

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]Andy[/TD]
[TD]Bob[/TD]
[TD]Jeff[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[TD]x[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Black[/TD]
[TD][/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Purple[/TD]
[TD][/TD]
[TD][/TD]
[TD]x[/TD]
[/TR]
[TR]
[TD]Green[/TD]
[TD]x[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Yellow[/TD]
[TD][/TD]
[TD]x[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Red[/TD]
[TD][/TD]
[TD][/TD]
[TD]x[/TD]
[/TR]
[TR]
[TD]Brown[/TD]
[TD]x[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Orange[/TD]
[TD][/TD]
[TD][/TD]
[TD]x[/TD]
[/TR]
</tbody>[/TABLE]

How can I get the output to be (or can I):

[TABLE="width: 500"]
<tbody>[TR]
[TD]Andy[/TD]
[TD]Bob[/TD]
[TD]Jeff[/TD]
[/TR]
[TR]
[TD]Blue[/TD]
[TD]Black[/TD]
[TD]Purple[/TD]
[/TR]
[TR]
[TD]Green[/TD]
[TD]Yellow[/TD]
[TD]Red[/TD]
[/TR]
[TR]
[TD]Brown[/TD]
[TD][/TD]
[TD]Orange[/TD]
[/TR]
</tbody>[/TABLE]

I am struggling to even figure out what to call this for research on the net... UNknown number of columns/rows...

Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
If you are interested in a VBA solution then,

Assuming the names start from B1, and colors start from A2
And you are looking at the data on "Sheet3" and outputting the summary on "Sheet4", this is what the code looks like:
Code:
Sub CollapseMatrix()
    lr = Worksheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
    lc = Worksheets("Sheet3").Cells(1, Columns.Count).End(xlToLeft).Column
    ColX = 2
    ColY = 1
    RowX = 1
    RowY = 1
    For i = ColX To lc
        For j = RowX To lr
            If j = 1 Then 'Transfer the name
                Worksheets("Sheet4").Cells(RowY, ColY).Value = Worksheets("Sheet3").Cells(j, i).Value
                RowY = RowY + 1
            ElseIf Worksheets("Sheet3").Cells(j, i).Value = "x" Then 'Transfer Colors
                Worksheets("Sheet4").Cells(RowY, ColY).Value = Worksheets("Sheet3").Range("A" & j).Value
                RowY = RowY + 1
            End If
        Next j
        RowY = 1
        ColY = ColY + 1
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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