Hi there!
I am fairly new to VBA in Excel and was hoping for some guidance on this problem. I am given hierarchical data from a database to perform a report, and the user would like to format the information such that an entry's children lie directly below it (a parent can have multiple children, child has only one parent). This could perhaps be done by indenting the Notes tab of the data by a few spaces. I was wondering how to first perform the reordering of the data by hierarchy, and then visually showing an indentation by adding, say, 5 spaces to the beginning of the Notes tab.
For sample data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Parent ID[/TD]
[TD]Notes[/TD]
[/TR]
[TR]
[TD]0[/TD]
[TD]NULL[/TD]
[TD]This is number 0.[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0[/TD]
[TD]This is number 1.[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]0[/TD]
[TD]This is number 2.[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]This is number 3.[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]3[/TD]
[TD]This is number 4.[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]0[/TD]
[TD]This is number 5.[/TD]
[/TR]
</tbody>[/TABLE]
I would then like the data to be presented as such:
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Parent ID[/TD]
[TD]Notes[/TD]
[/TR]
[TR]
[TD]0[/TD]
[TD]NULL[/TD]
[TD]This is number 0.[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0[/TD]
[TD]-----This is number 1.[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]0[/TD]
[TD]-----This is number 3.[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]1[/TD]
[TD]----------This is number 4.[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]-----This is number 2.[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]0[/TD]
[TD]-----This is number 5.[/TD]
[/TR]
</tbody>[/TABLE]
Thank you so much! Your help is greatly appreciated
I am fairly new to VBA in Excel and was hoping for some guidance on this problem. I am given hierarchical data from a database to perform a report, and the user would like to format the information such that an entry's children lie directly below it (a parent can have multiple children, child has only one parent). This could perhaps be done by indenting the Notes tab of the data by a few spaces. I was wondering how to first perform the reordering of the data by hierarchy, and then visually showing an indentation by adding, say, 5 spaces to the beginning of the Notes tab.
For sample data:
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Parent ID[/TD]
[TD]Notes[/TD]
[/TR]
[TR]
[TD]0[/TD]
[TD]NULL[/TD]
[TD]This is number 0.[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0[/TD]
[TD]This is number 1.[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]0[/TD]
[TD]This is number 2.[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]1[/TD]
[TD]This is number 3.[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]3[/TD]
[TD]This is number 4.[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]0[/TD]
[TD]This is number 5.[/TD]
[/TR]
</tbody>[/TABLE]
I would then like the data to be presented as such:
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Parent ID[/TD]
[TD]Notes[/TD]
[/TR]
[TR]
[TD]0[/TD]
[TD]NULL[/TD]
[TD]This is number 0.[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]0[/TD]
[TD]-----This is number 1.[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]0[/TD]
[TD]-----This is number 3.[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]1[/TD]
[TD]----------This is number 4.[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]-----This is number 2.[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]0[/TD]
[TD]-----This is number 5.[/TD]
[/TR]
</tbody>[/TABLE]
Thank you so much! Your help is greatly appreciated