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.

1DATA1MEMBER1
1DATA1MEMBER2
1DATA1MEMBER3
1DATA1MEMBER4
2DATA2MEMBER5
2DATA2MEMBER6
2DATA2MEMBER7
2DATA2MEMBER8
3DATA3MEMBER9
3DATA3MEMBER10
3DATA3MEMBER11
3DATA3MEMBER12

<tbody>
</tbody>

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

1DATA1MEMBER1MEMBER2MEMBER3MEMBER4
2DATA2MEMBER5MEMBER6MEMBER7MEMBER8
3DATA3MEMBER9MEMBER10MEMBER11MEMBER12

<tbody>
</tbody>

I need some help for a script or such thing to convert the first table to the requested one.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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

Forum statistics

Threads
1,216,119
Messages
6,128,947
Members
449,480
Latest member
yesitisasport

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