I am looking to write some code that will take a flat file and create a child/parent hierarchy from it. The flat file is sorted in order so that each new row is either a new level in the heirarchy or a new child member.
This is a sample of the sorted flat file from which the hierarch should be created:
This is the expected format of the hierarchy:
I am reasonably proficient in VBA but I am struggling with the correct logic to construct this hierarchy, as in should I be starting at the top or bottom of the flat file and how to create the cascading hierarchy. Any help appreciated.
This is a sample of the sorted flat file from which the hierarch should be created:
Book1 | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | Dimension | In/Out | Type | P# | L# | ||
2 | Contract | In | Pol | Prog1 | Prog1L1 | ||
3 | Contract | In | Pol | Prog1 | Prog1L2 | ||
4 | Contract | In | Pol | Prog1 | Prog1L3 | ||
5 | Contract | In | Pol | Prog2 | Prog2L1 | ||
6 | Contract | In | Pol | Prog2 | Prog2L2 | ||
7 | Contract | In | Pol | Prog2 | Prog2L3 | ||
8 | Contract | Out | NonPol | Prog3 | Prog3L1 | ||
Sheet2 |
This is the expected format of the hierarchy:
Book1 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
11 | Contract | Child | Parent | |||||||
12 | + | In | In | Contract | ||||||
13 | + | Pol | Pol | In | ||||||
14 | + | Prog1 | Prog1 | Pol | ||||||
15 | + | Prog1L1 | Prog1L1 | Prog1 | ||||||
16 | + | Prog1L2 | Prog1L2 | Prog1 | ||||||
17 | + | Prog1L3 | Prog1L3 | Prog1 | ||||||
18 | + | Prog2 | Prog2 | Pol | ||||||
19 | + | Prog2L1 | Prog2L1 | Prog2 | ||||||
20 | + | Prog2L2 | Prog2L2 | Prog2 | ||||||
21 | + | Prog2L3 | Prog2L3 | Prog2 | ||||||
22 | + | Out | Out | Contract | ||||||
23 | + | NonPol | NonPol | Out | ||||||
24 | + | Prog3 | Prog3 | NonPol | ||||||
25 | + | Prog3L1 | Prog3L1 | Prog3 | ||||||
Sheet2 |
I am reasonably proficient in VBA but I am struggling with the correct logic to construct this hierarchy, as in should I be starting at the top or bottom of the flat file and how to create the cascading hierarchy. Any help appreciated.