I have the table below and need help indenting parent child relationships. The root node starts at 0 and can traverse 1000+ levels deep as can the child relationships.
How do i achieve this in VBA?
CPackName CPackID PPackID PName ParentID PDATA
Artifacts 1 1 AC 0 297
Template 1 1 AC 0 281
WA 1 1 AC 0 361
Alisha 361 361 WA 1 611
Damian 361 361 WA 1 480
ABC 297 297 Artifacts 1
DEF 297 297 Artifacts 1
I would like to show this in columns as below.
The following Excel-VBA module works for me.
Just call
OutputIndentedRecords
passing in the range of the source data and the first cell of the output range.Let me know if you have any questions.
Here's how to setup a button to call this subroutine:
First, add the following VBA code to your subject worksheet's code module:
Change the Worksheet name above from "OutputWs" to whatever you output worksheet is named. also change the (2,2) to whatever the first output cell on that worksheet should be.
Next, go to your source worksheet and from the "Insert" menu, add a button/rectangular shape. Right-click it and pick "Assign Macro..", and then assign the
CallOutputIdent
macro to it.To use it, just select the input range and click the button. that should be it.