"Collapse" Matrix?
Attend Excelapalooza
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: "Collapse" Matrix?

  1. #1
    New Member
    Join Date
    Dec 2017
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default "Collapse" Matrix?

     
    Given the following

    Andy Bob Jeff
    Blue x
    Black x
    Purple x
    Green x
    Yellow x
    Red x
    Brown x
    Orange x

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

    Andy Bob Jeff
    Blue Black Purple
    Green Yellow Red
    Brown Orange

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

    Thanks!

  2. #2
    Board Regular iggydarsa's Avatar
    Join Date
    Jun 2005
    Location
    One of the Blue States
    Posts
    1,637
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: "Collapse" Matrix?

    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

  3. #3
    New Member
    Join Date
    Dec 2017
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: "Collapse" Matrix?

    Beautiful! Did you crank this out or just happen to have it lying around?

  4. #4
    Board Regular iggydarsa's Avatar
    Join Date
    Jun 2005
    Location
    One of the Blue States
    Posts
    1,637
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: "Collapse" Matrix?

      
    I cranked it out.

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com