anglais428
Well-known Member
- Joined
- Nov 23, 2009
- Messages
- 634
- Office Version
- 2016
- Platform
- Windows
Hello,
I would like to transpose the first table into the second table. The table will always begin in Cell A1 but could have varying row and column lengths. I have been toying with VBA but cannot find an appropriate solution.
Table 1 (original)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]TEST[/TD]
[TD]LOCATION[/TD]
[TD]2016A[/TD]
[TD]2016B[/TD]
[TD]2016C[/TD]
[TD]2017A[/TD]
[TD]2017B[/TD]
[TD]2017C[/TD]
[TD]2018A[/TD]
[TD]2018B[/TD]
[TD]2018C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]11[/TD]
[TD]12[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]20[/TD]
[TD]21[/TD]
[TD]22[/TD]
[TD]23[/TD]
[TD]24[/TD]
[TD]25[/TD]
[TD]26[/TD]
[TD]27[/TD]
[TD]28[/TD]
[/TR]
</tbody>[/TABLE]
Table 2 (desired output)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]TEST[/TD]
[TD]LOCATION[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]Year[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]2016[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]2017[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]11[/TD]
[TD]12[/TD]
[TD]13[/TD]
[TD]2018[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]20[/TD]
[TD]21[/TD]
[TD]22[/TD]
[TD]2016[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]23[/TD]
[TD]24[/TD]
[TD]25[/TD]
[TD]2017[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]26[/TD]
[TD]27[/TD]
[TD]28[/TD]
[TD]2017[/TD]
[/TR]
</tbody>[/TABLE]
Thanks.
I would like to transpose the first table into the second table. The table will always begin in Cell A1 but could have varying row and column lengths. I have been toying with VBA but cannot find an appropriate solution.
Table 1 (original)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]TEST[/TD]
[TD]LOCATION[/TD]
[TD]2016A[/TD]
[TD]2016B[/TD]
[TD]2016C[/TD]
[TD]2017A[/TD]
[TD]2017B[/TD]
[TD]2017C[/TD]
[TD]2018A[/TD]
[TD]2018B[/TD]
[TD]2018C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]11[/TD]
[TD]12[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]20[/TD]
[TD]21[/TD]
[TD]22[/TD]
[TD]23[/TD]
[TD]24[/TD]
[TD]25[/TD]
[TD]26[/TD]
[TD]27[/TD]
[TD]28[/TD]
[/TR]
</tbody>[/TABLE]
Table 2 (desired output)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]TEST[/TD]
[TD]LOCATION[/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]Year[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]5[/TD]
[TD]6[/TD]
[TD]7[/TD]
[TD]2016[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]8[/TD]
[TD]9[/TD]
[TD]10[/TD]
[TD]2017[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]UK[/TD]
[TD]11[/TD]
[TD]12[/TD]
[TD]13[/TD]
[TD]2018[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]20[/TD]
[TD]21[/TD]
[TD]22[/TD]
[TD]2016[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]23[/TD]
[TD]24[/TD]
[TD]25[/TD]
[TD]2017[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]USA[/TD]
[TD]26[/TD]
[TD]27[/TD]
[TD]28[/TD]
[TD]2017[/TD]
[/TR]
</tbody>[/TABLE]
Thanks.