Vertical to horizontal, repeating 4 records in each group

selant

Board Regular
Joined
Mar 26, 2009
Messages
109
In my file, each data group consists of 4 members. There are lots of groups in my worksheet.
Here is a demo data of first 3 group. "1" , "2" , "3" indicates unique flights.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]1[/TD]
[TD]DATA1[/TD]
[TD]MEMBER1[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]DATA1[/TD]
[TD]MEMBER2[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]DATA1[/TD]
[TD]MEMBER3[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]DATA1[/TD]
[TD]MEMBER4[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]DATA2[/TD]
[TD]MEMBER5[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]DATA2[/TD]
[TD]MEMBER6[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]DATA2[/TD]
[TD]MEMBER7[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]DATA2[/TD]
[TD]MEMBER8[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]DATA3[/TD]
[TD]MEMBER9[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]DATA3[/TD]
[TD]MEMBER10[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]DATA3[/TD]
[TD]MEMBER11[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]DATA3[/TD]
[TD]MEMBER12[/TD]
[/TR]
</tbody>[/TABLE]

I want to convert the data to a new table such as following :

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]1[/TD]
[TD]DATA1[/TD]
[TD]MEMBER1[/TD]
[TD]MEMBER2[/TD]
[TD]MEMBER3[/TD]
[TD]MEMBER4[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]DATA2[/TD]
[TD]MEMBER5[/TD]
[TD]MEMBER6[/TD]
[TD]MEMBER7[/TD]
[TD]MEMBER8[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]DATA3[/TD]
[TD]MEMBER9[/TD]
[TD]MEMBER10[/TD]
[TD]MEMBER11[/TD]
[TD]MEMBER12[/TD]
[/TR]
</tbody>[/TABLE]

I need some help for a script or such thing to convert the first table to the requested one.
 
Try this :- Results sheet2.
Code:
[COLOR="Navy"]Sub[/COLOR] MG28Aug56
[COLOR="Navy"]Dim[/COLOR] Rng     [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn      [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] n       [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] oMax    [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] K
[COLOR="Navy"]Dim[/COLOR] c       [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Ac      [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] col     [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Twn     [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
c = 1
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Twn = Dn & "," & Dn.Offset(, 1)
    [COLOR="Navy"]If[/COLOR] Not .Exists(Twn) [COLOR="Navy"]Then[/COLOR]
        .Add Twn, Dn
    [COLOR="Navy"]Else[/COLOR]
        [COLOR="Navy"]Set[/COLOR] .Item(Twn) = Union(.Item(Twn), Dn)
        oMax = Application.Max(oMax, .Item(Twn).Count)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]For[/COLOR] n = 1 To oMax
    [COLOR="Navy"]With[/COLOR] Sheets("Sheet2")
        '[COLOR="Green"][B] Alter Headers to names suit ####[/B][/COLOR]
        .Cells(1, 1) = "No" '[COLOR="Green"][B] ####[/B][/COLOR]
        .Cells(1, 2) = "Data" '[COLOR="Green"][B]####[/B][/COLOR]
        .Cells(1, n + 2) = "Member" & n '[COLOR="Green"][B]####[/B][/COLOR]
    [COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
    col = 2
    c = c + 1
    Sheets("Sheet2").Cells(c, 1) = Split(K, ",")(0)
    Sheets("Sheet2").Cells(c, 2) = Split(K, ",")(1)
    Sheets("Sheet2").Cells(c, 3).Resize(, .Item(K).Count).Value = Application.Transpose(.Item(K).Offset(, 2).Value)
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

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