I have the following four columns, where I need to iterate over 'item':
parentID parent itemID item
398735 Papa 398713 Alpha
398735 Papa 399270 Bravo
398735 Papa 399822 Charlie
398731 Lima 398732 Delta
398731 Lima 398733 Echo
398733 Echo 66359 Foxtrot
398733 Echo 66360 Golf
398733 Echo 66361 Hotel
398733 Echo 66362 India
398733 Echo 66363 Juliett
398733 Echo 66364 Kilo
398730 Root 66281 Mike
398730 Root 66283 November
398730 Root 398731 Lima
398730 Root 398734 Oscar
398734 Oscar 398735 Papa
398734 Oscar 66281 Quebec
I want to generate a dynamic hierarchy (tree-like structure), like so:
Mike
November
Lima
Delta
Echo
Foxtrot
Golf
Hotel
India
Juliett
Kilo
Oscar
Papa
Alpha
Bravo
Charlie
Quebec
If this was in Python for example, it would be extremely easy to create a hierarchy by iterating over my items, looking to see if its a parent (root if not), and using a dictionary to store all this information, then build this structure on an excel sheet by iterating over the dictionary. However, for the purposes of this Macro I have no idea how to even do a simple column lookup, let alone use a dictionary.
My theory is to:
1) Begin by somehow iterating over the four "roots", and store them as keys with null values in dict1.
2) For each root, update it's value in dict1 to be an array of immediate children.
3) Then, for each child of each root, create another dictionary (dict2) where all keys are all the root-children.
4) Iterate over dict2 keys and set each key value to an array of children.
5) Iterate over dict1, write everything, reference dict2 as you go for further children.
Can this be implemented in VBA elegantly?