convert data from horizontal to vertical

premsi

New Member
Joined
Apr 8, 2018
Messages
8
Could someone please help me with vba coding for the below excel query

raw data

[TABLE="width: 384"]
<colgroup><col width="64" span="6" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]name[/TD]
[TD="class: xl65, width: 64"]score[/TD]
[TD="class: xl65, width: 64"]name[/TD]
[TD="class: xl65, width: 64"]score[/TD]
[TD="class: xl65, width: 64"]name[/TD]
[TD="class: xl65, width: 64"]score[/TD]
[/TR]
[TR]
[TD="class: xl65"]zen[/TD]
[TD="class: xl65"]32[/TD]
[TD="class: xl65"]men[/TD]
[TD="class: xl65"]22[/TD]
[TD="class: xl65"]ken[/TD]
[TD="class: xl65"]58[/TD]
[/TR]
[TR]
[TD="class: xl65"]ran[/TD]
[TD="class: xl65"]45[/TD]
[TD="class: xl65"]den[/TD]
[TD="class: xl65"]23[/TD]
[TD="class: xl65"]shen[/TD]
[TD="class: xl65"]56[/TD]
[/TR]
[TR]
[TD="class: xl65"]connor[/TD]
[TD="class: xl65"]66[/TD]
[TD="class: xl65"]junior[/TD]
[TD="class: xl65"]24[/TD]
[TD="class: xl65"]zenith[/TD]
[TD="class: xl65"]25[/TD]
[/TR]
</tbody>[/TABLE]

Seeking the refine data as below

[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]name[/TD]
[TD="class: xl65, width: 64"]score[/TD]
[/TR]
[TR]
[TD="class: xl65"]zen[/TD]
[TD="class: xl65"]32[/TD]
[/TR]
[TR]
[TD="class: xl65"]ran[/TD]
[TD="class: xl65"]45[/TD]
[/TR]
[TR]
[TD="class: xl65"]connor[/TD]
[TD="class: xl65"]66[/TD]
[/TR]
[TR]
[TD="class: xl65"]name[/TD]
[TD="class: xl65"]score[/TD]
[/TR]
[TR]
[TD="class: xl65"]men[/TD]
[TD="class: xl65"]22[/TD]
[/TR]
[TR]
[TD="class: xl65"]den[/TD]
[TD="class: xl65"]23[/TD]
[/TR]
[TR]
[TD="class: xl65"]junior[/TD]
[TD="class: xl65"]24[/TD]
[/TR]
[TR]
[TD="class: xl65"]name[/TD]
[TD="class: xl65"]score[/TD]
[/TR]
[TR]
[TD="class: xl65"]ken[/TD]
[TD="class: xl65"]58[/TD]
[/TR]
[TR]
[TD="class: xl65"]shen[/TD]
[TD="class: xl65"]56[/TD]
[/TR]
[TR]
[TD="class: xl65"]zenith[/TD]
[TD="class: xl65"]25[/TD]
[/TR]
</tbody>[/TABLE]

Thanks in advance!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this:-
Results start "K1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG08Apr59
[COLOR="Navy"]Dim[/COLOR] Ray, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
 Ray = ActiveSheet.Cells(1).CurrentRegion
  ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2), 1 To 2)
[COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray, 2) [COLOR="Navy"]Step[/COLOR] 2
    [COLOR="Navy"]For[/COLOR] n = 1 To UBound(Ray, 1)
        c = c + 1
        nray(c, 1) = Ray(n, Ac)
        nray(c, 2) = Ray(n, Ac + 1)
    [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] Ac
Range("K1").Resize(c, 2).Value = nray
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:-
Results start "K1".
Code:
[COLOR=Navy]Sub[/COLOR] MG08Apr59
[COLOR=Navy]Dim[/COLOR] Ray, Ac [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] n [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] c [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long[/COLOR]
 Ray = ActiveSheet.Cells(1).CurrentRegion
  ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2), 1 To 2)
[COLOR=Navy]For[/COLOR] Ac = 1 To UBound(Ray, 2) [COLOR=Navy]Step[/COLOR] 2
    [COLOR=Navy]For[/COLOR] n = 1 To UBound(Ray, 1)
        c = c + 1
        nray(c, 1) = Ray(n, Ac)
        nray(c, 2) = Ray(n, Ac + 1)
    [COLOR=Navy]Next[/COLOR] n
[COLOR=Navy]Next[/COLOR] Ac
Range("K1").Resize(c, 2).Value = nray
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick[/Thank you so much Mick, you made my day!]
 
Upvote 0

Forum statistics

Threads
1,226,695
Messages
6,192,478
Members
453,727
Latest member
tuong_ng89

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