Code for converting data into a particular format

kaushik_birmiwal

New Member
Joined
Feb 6, 2017
Messages
9
Hi All,

I have been facing this recurring issue. We need to analyze the spend as per product and SKU by week, months, quarters etc. The dump from the tool is in a raw form and we end up spending lot of time in converting the data into a format which can be further used to apply pivots. I am relatively new to coding and hence would like to seek help.

I have the data in below format:

[TABLE="width: 517"]
<tbody>[TR]
[TD]Month[/TD]
[TD]Year[/TD]
[TD]January[/TD]
[TD]January[/TD]
[TD]January[/TD]
[TD]January[/TD]
[TD]January[/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]2016[/TD]
[TD]1[/TD]
[TD]8[/TD]
[TD]15[/TD]
[TD]22[/TD]
[TD]29[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Week No.[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]AB[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]2016[/TD]
[TD]SKU 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]SKU 2[/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD]SKU 3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD]SKU 5[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]SKU 6[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 1[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]Planned[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 3[/TD]
[TD]Rental[/TD]
[TD="align: right"]$6,000[/TD]
[TD="align: right"]$17,655[/TD]
[TD="align: right"]$5,000[/TD]
[TD="align: right"]$40,000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 4[/TD]
[TD]listing fee[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 5[/TD]
[TD]production cost[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CD[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD]SKU 7[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD]SKU 11[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]2016[/TD]
[TD]SKU 8[/TD]
[TD][/TD]
[TD]SKU 9[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]SKU 10[/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]2016[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]Planned[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]Rental[/TD]
[TD="align: right"]$6,000[/TD]
[TD="align: right"]$17,655[/TD]
[TD][/TD]
[TD="align: right"]$40,000[/TD]
[TD="align: right"]$5,000[/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]listing fee[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Product 2[/TD]
[TD]production cost[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


I now need to convert this data into the below mentioned format, so that i can pivots for analyzing the data.

[TABLE="width: 568"]
<tbody>[TR]
[TD]Year[/TD]
[TD]Product Category[/TD]
[TD]Product[/TD]
[TD]Week[/TD]
[TD]SKU #[/TD]
[TD]Amount[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]AB[/TD]
[TD]Product 1[/TD]
[TD]1[/TD]
[TD]SKU 1[/TD]
[TD]$6,000[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]AB[/TD]
[TD]Product 1[/TD]
[TD]1[/TD]
[TD]SKU 7[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]AB[/TD]
[TD]Product 1[/TD]
[TD]3[/TD]
[TD]SKU 5[/TD]
[TD]$5,000[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]AB[/TD]
[TD]Product 1[/TD]
[TD]4[/TD]
[TD]SKU 6[/TD]
[TD]$40,000[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]AB[/TD]
[TD]Product 1[/TD]
[TD]5[/TD]
[TD]SKU 2[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]AB[/TD]
[TD]Product 1[/TD]
[TD]2[/TD]
[TD]SKU 13[/TD]
[TD]$17,655[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]AB[/TD]
[TD]Product 1[/TD]
[TD]2[/TD]
[TD]SKU 3[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]CD[/TD]
[TD]Product 2[/TD]
[TD]1[/TD]
[TD]SKU 8[/TD]
[TD]$6,000[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]CD[/TD]
[TD]Product 2[/TD]
[TD]2[/TD]
[TD]SKU 12[/TD]
[TD]$17,655[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]CD[/TD]
[TD]Product 2[/TD]
[TD]3[/TD]
[TD]SKU 11[/TD]
[TD]-[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]CD[/TD]
[TD]Product 2[/TD]
[TD]3[/TD]
[TD]SKU 9[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]CD[/TD]
[TD]Product 2[/TD]
[TD]5[/TD]
[TD]SKU 10[/TD]
[TD]$5,000[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]CD[/TD]
[TD]Product 2[/TD]
[TD]4[/TD]
[TD]NA[/TD]
[TD]$40,000[/TD]
[/TR]
</tbody>[/TABLE]




Can someone please help me with this issue.

Thanks in advance.

Regards,
Kaushik
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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