Hi everyone,
Very frequently I have economic databases in the following format in excel:
[TABLE="width: 345"]
<colgroup><col span="5"></colgroup><tbody>[TR]
[TD]Country[/TD]
[TD]2010[/TD]
[TD]2011[/TD]
[TD]2012[/TD]
[TD]2013[/TD]
[/TR]
[TR]
[TD]China[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]US[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]EU[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6
[/TD]
[/TR]
</tbody>[/TABLE]
In this case, each of the values in the table are based on formulas in other worksheets.
I would like to have a macro to transpose this database (in this same worksheet or a new worksheet) to the following format:
[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl66, width: 64"]Year[/TD]
[TD="class: xl66, width: 64"]Country[/TD]
[TD="class: xl66, width: 64"]Value[/TD]
[/TR]
[TR]
[TD="class: xl66"]2010[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]1[/TD]
[/TR]
[TR]
[TD="class: xl66"]2011[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]2[/TD]
[/TR]
[TR]
[TD="class: xl66"]2012[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]3[/TD]
[/TR]
[TR]
[TD="class: xl66"]2013[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]4[/TD]
[/TR]
[TR]
[TD="class: xl66"]2010[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]2[/TD]
[/TR]
[TR]
[TD="class: xl66"]2011[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]3[/TD]
[/TR]
[TR]
[TD="class: xl66"]2012[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]4[/TD]
[/TR]
[TR]
[TD="class: xl66"]2013[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]5[/TD]
[/TR]
[TR]
[TD="class: xl66"]2010[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]3[/TD]
[/TR]
[TR]
[TD="class: xl66"]2011[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]4[/TD]
[/TR]
[TR]
[TD="class: xl66"]2012[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]5[/TD]
[/TR]
[TR]
[TD="class: xl66"]2013[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]6[/TD]
[/TR]
</tbody>[/TABLE]
In this case, the exact formulas have to transfer as well. This is crucial.
In addition, the macro should work regardless of the number of columns and rows in the initial database (sometimes the time period is 1961-2013 and I have as many as 100 countries).
Any suggestions?
Much appreciated!
Very frequently I have economic databases in the following format in excel:
[TABLE="width: 345"]
<colgroup><col span="5"></colgroup><tbody>[TR]
[TD]Country[/TD]
[TD]2010[/TD]
[TD]2011[/TD]
[TD]2012[/TD]
[TD]2013[/TD]
[/TR]
[TR]
[TD]China[/TD]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]US[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]EU[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]6
[/TD]
[/TR]
</tbody>[/TABLE]
In this case, each of the values in the table are based on formulas in other worksheets.
I would like to have a macro to transpose this database (in this same worksheet or a new worksheet) to the following format:
[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl66, width: 64"]Year[/TD]
[TD="class: xl66, width: 64"]Country[/TD]
[TD="class: xl66, width: 64"]Value[/TD]
[/TR]
[TR]
[TD="class: xl66"]2010[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]1[/TD]
[/TR]
[TR]
[TD="class: xl66"]2011[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]2[/TD]
[/TR]
[TR]
[TD="class: xl66"]2012[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]3[/TD]
[/TR]
[TR]
[TD="class: xl66"]2013[/TD]
[TD="class: xl66"]China[/TD]
[TD="class: xl66"]4[/TD]
[/TR]
[TR]
[TD="class: xl66"]2010[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]2[/TD]
[/TR]
[TR]
[TD="class: xl66"]2011[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]3[/TD]
[/TR]
[TR]
[TD="class: xl66"]2012[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]4[/TD]
[/TR]
[TR]
[TD="class: xl66"]2013[/TD]
[TD="class: xl66"]US[/TD]
[TD="class: xl66"]5[/TD]
[/TR]
[TR]
[TD="class: xl66"]2010[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]3[/TD]
[/TR]
[TR]
[TD="class: xl66"]2011[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]4[/TD]
[/TR]
[TR]
[TD="class: xl66"]2012[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]5[/TD]
[/TR]
[TR]
[TD="class: xl66"]2013[/TD]
[TD="class: xl66"]EU[/TD]
[TD="class: xl66"]6[/TD]
[/TR]
</tbody>[/TABLE]
In this case, the exact formulas have to transfer as well. This is crucial.
In addition, the macro should work regardless of the number of columns and rows in the initial database (sometimes the time period is 1961-2013 and I have as many as 100 countries).
Any suggestions?
Much appreciated!