oceanBreeze
New Member
- Joined
- Jul 18, 2019
- Messages
- 2
Hello all,
I have searched for a few days now how to unpivot via VBA. While I have found some helpful information out there, my situation is unique in that the desire is to unpivot nested headers. Horizontal groupings have levels. For example, below is simple example of what I am trying to do. The Current state is nested header data. I want that data in flattened form so we can import into other tools such as a database or visualization tools.
I would prefer to do this via VBA and not power query or power bi. In the details below there are 2 header levels (Quarters and Forecast and yes they are different values), but it could potentially be groupings up to 6 or even 7.
Does ANYONE know how to do this via VBA with an ability to adjust to include more nested headers??? Please please help!
Current State:
[TABLE="class: text_table"]
<tbody style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline;">[TR]
[TD][/TD]
[TD="width: 117"]QUARTER 1[/TD]
[TD="width: 111"]QUARTER 2[/TD]
[TD="width: 97"]QUARTER 3[/TD]
[TD="width: 94"]QUARTER 4[/TD]
[TD="width: 94"]QUARTER 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]4Q17 Forecast[/TD]
[TD]4Q17 Forecast[/TD]
[TD]4Q17 Forecast[/TD]
[TD]4Q17 Forecast[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]124332342.00[/TD]
[TD]234.67[/TD]
[TD]234.23[/TD]
[TD]23.60[/TD]
[TD]0.00[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]89435.98[/TD]
[TD]628.00[/TD]
[TD]112374.29[/TD]
[TD]0.00[/TD]
[TD]347.34[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]548734.34[/TD]
[TD]872536.45[/TD]
[TD]0.00[/TD]
[TD]21.96[/TD]
[TD]124.64[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]0.00[/TD]
[TD]7893425675.34[/TD]
[TD]7678254.67[/TD]
[TD]0.00[/TD]
[TD]6591.00[/TD]
[/TR]
</tbody>[/TABLE]
Desired State:[TABLE="class: text_table"]
<tbody style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline;">[TR]
[TD]Credit1[/TD]
[TD="width: 117"]124332342.00[/TD]
[TD="width: 111"]QUARTER 1[/TD]
[TD="width: 97"]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]89435.98[/TD]
[TD]QUARTER 1[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]548734.34[/TD]
[TD]QUARTER 1[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]0.00[/TD]
[TD]QUARTER 1[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]234.67[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]628.00[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]872536.45[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]7893425675.34[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]234.23[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]112374.29[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]0.00[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]7678254.67[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]23.60[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]0.00[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]21.96[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]0.00[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]0.00[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]347.34[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]124.64[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]6591.00[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
</tbody>[/TABLE]
I have searched for a few days now how to unpivot via VBA. While I have found some helpful information out there, my situation is unique in that the desire is to unpivot nested headers. Horizontal groupings have levels. For example, below is simple example of what I am trying to do. The Current state is nested header data. I want that data in flattened form so we can import into other tools such as a database or visualization tools.
I would prefer to do this via VBA and not power query or power bi. In the details below there are 2 header levels (Quarters and Forecast and yes they are different values), but it could potentially be groupings up to 6 or even 7.
Does ANYONE know how to do this via VBA with an ability to adjust to include more nested headers??? Please please help!
Current State:
[TABLE="class: text_table"]
<tbody style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline;">[TR]
[TD][/TD]
[TD="width: 117"]QUARTER 1[/TD]
[TD="width: 111"]QUARTER 2[/TD]
[TD="width: 97"]QUARTER 3[/TD]
[TD="width: 94"]QUARTER 4[/TD]
[TD="width: 94"]QUARTER 1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]4Q17 Forecast[/TD]
[TD]4Q17 Forecast[/TD]
[TD]4Q17 Forecast[/TD]
[TD]4Q17 Forecast[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]124332342.00[/TD]
[TD]234.67[/TD]
[TD]234.23[/TD]
[TD]23.60[/TD]
[TD]0.00[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]89435.98[/TD]
[TD]628.00[/TD]
[TD]112374.29[/TD]
[TD]0.00[/TD]
[TD]347.34[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]548734.34[/TD]
[TD]872536.45[/TD]
[TD]0.00[/TD]
[TD]21.96[/TD]
[TD]124.64[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]0.00[/TD]
[TD]7893425675.34[/TD]
[TD]7678254.67[/TD]
[TD]0.00[/TD]
[TD]6591.00[/TD]
[/TR]
</tbody>[/TABLE]
Desired State:[TABLE="class: text_table"]
<tbody style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; vertical-align: baseline;">[TR]
[TD]Credit1[/TD]
[TD="width: 117"]124332342.00[/TD]
[TD="width: 111"]QUARTER 1[/TD]
[TD="width: 97"]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]89435.98[/TD]
[TD]QUARTER 1[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]548734.34[/TD]
[TD]QUARTER 1[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]0.00[/TD]
[TD]QUARTER 1[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]234.67[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]628.00[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]872536.45[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]7893425675.34[/TD]
[TD]QUARTER 2[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]234.23[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]112374.29[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]0.00[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]7678254.67[/TD]
[TD]QUARTER 3[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]23.60[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]0.00[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]21.96[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]0.00[/TD]
[TD]QUARTER 4[/TD]
[TD]4Q17 Forecast[/TD]
[/TR]
[TR]
[TD]Credit1[/TD]
[TD]0.00[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]Equity1[/TD]
[TD]347.34[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]RiskAndCredit2[/TD]
[TD]124.64[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
[TR]
[TD]EstatePlanning[/TD]
[TD]6591.00[/TD]
[TD]QUARTER 1[/TD]
[TD]1Q18 Forecast[/TD]
[/TR]
</tbody>[/TABLE]