Build parent/child hierarchy

  • Hello,


    I kindly ask for your support because I have to achieve something that seems to be simple but I just can't figure it out how to do it.


    Mainly, I have two columns. The first one contains some parent codes, the second one contains some child codes which can consequently become parent codes for other child codes. And so on.


    Having this in mind, I want to create a hierarchy like the one form the example file (see attachment). The example file was created manually with a minimum number of records but the final database can be way bigger.


    Thank you in advance for your support!
    A.B.


    Also posted here:
    http://www.vbaexpress.com/forum/showthread.php?57247-Build-parent-child-hierarchy
    http://www.mrexcel.com/forum/e….html#post4639220</a><br>

  • Re: Build parent/child hierarchy


    The duplicate pairs (AB00002 & AB00005) plus AB00007 being a child of both AB00002 & AB00003 makes it difficult to devise an accurate solution in code. Please explain the logic behind the groupings.

  • Re: Build parent/child hierarchy


    Hey cytop,


    These are only mistakes...in reality there will be no duplicate and no child can be allocated to more than one parent.
    Please excuse my bad example. The correct table should be like this:


    [TABLE="width: 576"]

    [tr]


    [TD="class: xl65, width: 64"]Parent[/TD]
    [TD="class: xl65, width: 64"]Child[/TD]
    [TD="width: 64"][/TD]
    [TD="width: 64"][/TD]
    [TD="width: 64"][/TD]
    [TD="width: 64"][/TD]
    [TD="width: 64"][/TD]
    [TD="width: 64"][/TD]
    [TD="width: 64"][/TD]

    [/tr]


    [tr]


    [td]

    AB00000

    [/td]


    [td]

    AB00001

    [/td]


    [td][/td]


    [td]

    AB00000

    [/td]


    [td]

    AB00001

    [/td]


    [td]

    AB00002

    [/td]


    [td]

    AB00005

    [/td]


    [td]

    AB00009

    [/td]


    [td]

    AB00010

    [/td]


    [/tr]


    [tr]


    [td]

    AB00001

    [/td]


    [td]

    AB00002

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td]

    AB00006

    [/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00001

    [/td]


    [td]

    AB00003

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td]

    AB00007

    [/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00001

    [/td]


    [td]

    AB00004

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td]

    AB00003

    [/td]


    [td]

    AB00011

    [/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00002

    [/td]


    [td]

    AB00005

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td]

    AB00004

    [/td]


    [td]

    AB00008

    [/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00002

    [/td]


    [td]

    AB00006

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00002

    [/td]


    [td]

    AB00007

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00003

    [/td]


    [td]

    AB00011

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00004

    [/td]


    [td]

    AB00008

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00005

    [/td]


    [td]

    AB00009

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    AB00009

    [/td]


    [td]

    AB00010

    [/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [/TABLE]



    Thanks!

  • Re: Build parent/child hierarchy


    Sorry cytop for putting you on a wrong path.
    The solution provided by Mike on the other forum works indeed for my example but there are still some problems with my database and I have to solve them before giving some more wrong premises.
    It seems that it was a misunderstanding between me and my colleague which gave me the requests.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!