VBA help with re-arranging data table

Nhoj01

New Member
Joined
Jan 6, 2016
Messages
13
Currently faced with the following issue, and can't figure out a solution so thought I'd ask the experts :)

Data looks like this currently:
IDSerialSerialSerialSerialSerialSerialSerialSerialSerial
1234
12345678

<tbody>
</tbody>
12345679

<tbody>
</tbody>
12345680

<tbody>
</tbody>
12345681

<tbody>
</tbody>
12345682

<tbody>
</tbody>
12345683

<tbody>
</tbody>
12345684

<tbody>
</tbody>
12345685

<tbody>
</tbody>
12345686

<tbody>
</tbody>
1235123456781234567912345680123456811234568212345683
12361234567812345679123456801234568112345682123456831234568412345685

<tbody>
</tbody>


Goal is to get the data looking like this:
IDSerial
1234
12345678

<tbody>
</tbody>
1234
12345679

<tbody>
</tbody>
1234
12345680

<tbody>
</tbody>
1234
12345681

<tbody>
</tbody>
1234
12345682

<tbody>
</tbody>
1234
12345683

<tbody>
</tbody>
1234
12345684

<tbody>
</tbody>
1234
12345685

<tbody>
</tbody>
1234
12345686

<tbody>
</tbody>
1235
12345678

<tbody>
</tbody>
1235
12345679

<tbody>
</tbody>
1235
12345680

<tbody>
</tbody>
1235
12345681

<tbody>
</tbody>
1235
12345682

<tbody>
</tbody>
1235
12345683

<tbody>
</tbody>
1236
12345678

<tbody>
</tbody>
1236
12345679

<tbody>
</tbody>
1236
12345680

<tbody>
</tbody>
1236
12345681

<tbody>
</tbody>
1236
12345682

<tbody>
</tbody>
1236
12345683

<tbody>
</tbody>
1236
12345684

<tbody>
</tbody>
1236
12345685

<tbody>
</tbody>

<tbody>
</tbody>

Any ideas?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
This code Assumes there are no Blank Cells in column "A" Data.
Results start sheet2 ,"A1"
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Jan28
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, Rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
 Ray = ActiveSheet.Range("A1").CurrentRegion
  ReDim nRay(1 To UBound(Ray, 1) * UBound(Ray, 2) + 1, 1 To 2)
    nRay(1, 1) = "ID": nRay(1, 2) = "Serial"
    c = 1
    [COLOR="Navy"]For[/COLOR] Rw = 2 To UBound(Ray, 1)
        [COLOR="Navy"]For[/COLOR] Ac = 2 To UBound(Ray, 2)
              [COLOR="Navy"]If[/COLOR] Not Ray(Rw, Ac) = vbNullString [COLOR="Navy"]Then[/COLOR]
                  c = c + 1
                  nRay(c, 1) = Ray(Rw, 1)
                  nRay(c, 2) = Ray(Rw, Ac)
              [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] Ac
  [COLOR="Navy"]Next[/COLOR] Rw
Sheets("Sheet2").Range("A1").Resize(c, 2) = nRay
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,216,029
Messages
6,128,404
Members
449,448
Latest member
Andrew Slatter

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