I'm looking to transpose a spreadsheet that consists of a column with an ID for the whole row of data, followed by data fields listed in a typical column/row setup, similar to the table below. And for background, my particular data set has thousands of rows and about 20 or so columns.
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Name[/TD]
[TD]Field 1[/TD]
[TD]Field 2[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A[/TD]
[TD]X[/TD]
[TD]345[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]Y[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
However, due to a limitation of the system this data will be used in, I need to alter this structure to an alternate format where I list out the ID, the field name, followed by the answer for that field, similar to the following:
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Field[/TD]
[TD]Answer[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Field 1[/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Field 2[/TD]
[TD]345[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Name[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Field 1[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Field 2[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
So to solve this transformation via VBA I'm thinking I need to do the following:
Is this the right approach? Any thoughts, ideas, or code examples are greatly appreciated.
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Name[/TD]
[TD]Field 1[/TD]
[TD]Field 2[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]A[/TD]
[TD]X[/TD]
[TD]345[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]B[/TD]
[TD]Y[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
However, due to a limitation of the system this data will be used in, I need to alter this structure to an alternate format where I list out the ID, the field name, followed by the answer for that field, similar to the following:
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Field[/TD]
[TD]Answer[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Field 1[/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Field 2[/TD]
[TD]345[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Name[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Field 1[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Field 2[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
So to solve this transformation via VBA I'm thinking I need to do the following:
- transpose the field listing into column 2
- have it fill ID 1 out in front of the transposed field names
- transpose the field data into column 3
- then have it repeat for each subsequent number
Is this the right approach? Any thoughts, ideas, or code examples are greatly appreciated.