Results 1 to 9 of 9

Thread: Convert Matrix Style Data into Stacked Rows preserving identifying row values

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Rep Power
    0

    Convert Matrix Style Data into Stacked Rows preserving identifying row values

    Hi All,

    I have found some solutions here that are very similar to what I need, but can't quite get them to work.

    The issue is that I have sets of data arranged in a matrix style that I need to convert to stacked rows while keeping certain row values with each resulting new row. Tough to explain, but apparently a fairly common issue. If you can, please help me.

    ForumExample.jpg
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    Code:
    Sub M_snb()
       sn = Cells(1).CurrentRegion
       sp = Cells(1).CurrentRegion.Resize(, 10)
       
       c00 = 1
       For j = 2 To UBound(sn)
         c00 = c00 & Replace(String(17, "|"), "|", "|" & j)
       Next
       
       sq = Application.Index(sp, Application.Transpose(Split(c00, "|")), [transpose(row(1:10))])
       
       For j = 2 To UBound(sq)
          sq(j, 9) = "Brand " & (j - 2) Mod (17) + 1
          sq(j, 10) = sn((j + 15) \ 17 + 1, 8 + (j - 2) Mod (17) + 1)
       Next
       
       Cells(40, 1).Resize(UBound(sq), UBound(sq, 2)) = sq
    End Sub

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Rep Power
    0
    Thank you so much snb. This is exactly what I needed. I can't tell you how much I appreciate your help!!!!!! And on a Friday afternoon no less!!

    If you happen to see this again, I have a few follow up Q's.

    1. Can you recommend some reading material or tutorials that I might use to educate my self on the writing of macros?
    2. Can you easily modify this code to exclude rows that result in no value?
    3. Can the code be modified to include an if/than type statement such that entries marked "Do Not Re-Accrue" are excluded from the result (thereby eliminating the step I made before posting that dataset, which was to filter on "Accrue/Re-Accrue" and then copy/paste values into another sheet?

    Again, thank you so much. You just made my life a little easier (and month end close!!).

  4. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Rep Power
    0
    One other thing....when this dataset occupies many more rows, will this same code still work or will I need to modify a part of it to define the last row of the dataset?

    Thank you.

  5. #5
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    ad 1. Green, Bullen, Bovey, Alexander Excel 2007 VBA; Programmer's Reference ISBN 978-0-470-04643-2

    ad 2 & ad 3
    Code:
    Sub M_snb()
       sn = Cells(1).CurrentRegion
       sp = Cells(1).CurrentRegion.Resize(, 10)
       
       c00 = 1
       For j = 2 To UBound(sn)
         if(lcase(sn(j,1))="accrue" then c00 = c00 & Replace(String(17, "|"), "|", "|" & j)
       Next
       
       sq = Application.Index(sp, Application.Transpose(Split(c00, "|")), [transpose(row(1:10))])
       
       For j = 2 To UBound(sq)
          sq(j, 9) = "Brand " & (j - 2) Mod (17) + 1
          sq(j, 10) = sn((j + 15) \ 17 + 1, 8 + (j - 2) Mod (17) + 1)
       Next
       
       Cells(40, 1).Resize(UBound(sq), UBound(sq, 2)) = sq
    End Sub.
    ad 4. No need to adapt for larger datasets as long as no empty row/column makes part of it.
    Last edited by snb; 09-03-2014 at 01:22 PM.

  6. #6
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Rep Power
    0
    Again, thank you snb, you're great. I appreciate your time and help very much.

    I have one more dilemma that you may be able to address.

    It seems you have the word "Brand" hardcoded in the code to add sequential numerals thus leading to the headings in this example..... "Brand 1..Brand 2...Brand 3..) but I actually need the code to use the exact name that is populated across the column headers because in practice those place holders will actually be named with real product brands.
    .
    Can you give me one more revamp with references to the actual names populating the columns?

    Thank you Sir/Ma'am. Again, much appreciate your time and effort.

  7. #7
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    From where do those 'actual names' originate ?

  8. #8
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Rep Power
    0
    Quote Originally Posted by snb View Post
    From where do those 'actual names' originate ?


    Hi snb....the 'actual names' are populated across the column headers. In this example I just typed in Brand1, Brand2, etc...but in practice these will be actual products names like Gorilla, BigOne, Masher...etc

    The code will need to obtain the names from the text in the first row along the columns.

    God I hope you can help me bro. I ran out of time and need to do this work tomorrow.

    Thank you so much.

  9. #9
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    Did you try:

    Code:
    Sub M_snb()
       sn = Cells(1).CurrentRegion
       sp = Cells(1).CurrentRegion.Resize(, 10)
       
       c00 = 1
       For j = 2 To UBound(sn)
         If (LCase(sn(j, 1))) = "accrue" Then c00 = c00 & Replace(String(17, "|"), "|", "|" & j)
       Next
       
       sq = Application.Index(sp, Application.Transpose(Split(c00, "|")), [transpose(row(1:10))])
       
       For j = 2 To UBound(sq)
          sq(j, 9) = sn(1, 8 + (j - 2) Mod 17 + 1)
          sq(j, 10) = sn((j + 15) \ 17 + 1, 8 + (j - 2) Mod (17) + 1)
       Next
       
       Cells(40, 1).Resize(UBound(sq), UBound(sq, 2)) = sq
    End Sub

Similar Threads

  1. Replies: 2
    Last Post: 03-08-2014, 02:49 AM
  2. Replies: 6
    Last Post: 12-23-2013, 04:07 PM
  3. Skip empty row and fetch values from other rows
    By dhivya.enjoy in forum Excel Help
    Replies: 1
    Last Post: 11-08-2013, 07:44 PM
  4. Replies: 10
    Last Post: 08-31-2013, 06:56 PM
  5. Group Pivot Data Based On Row Values In One Column
    By mrmmickle1 in forum Excel Help
    Replies: 10
    Last Post: 10-09-2012, 11:46 PM

Posting Permissions

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