Extracting multi level connection from parent and child column

shriexcel

New Member
Joined
Sep 21, 2017
Messages
1
Greetings All,

i have data set consisting of parent and child connections. I need to find a way to extract parent its child and its child's child and so on. Data structure is like this

ParentChild
AB
AC
BD
CE
CF
FG
FH
FI
GJ
GK

<tbody>
</tbody>
My formula is very rough and takes so much time to run it. I am looking for a faster way to make this connection.
My code runs the loop find top parent
Run the loop and find where child is parent
print out both the information and keeps on going.

My data has almost 8000-10000 lines and running the loop through them again and again is taking time (almost 15 minutes) and crashing my excel.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Perhaps this:-
Results in Column "D".
Code:
[COLOR="Navy"]Sub[/COLOR] MG22Sep24
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] K, oVal [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String,[/COLOR] Nstr [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
c = 1
Range("D1").Value = "P to C"
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
    [COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
        .CompareMode = vbTextCompare
            [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng: .Item(Dn.Value) = Dn.Offset(, -1).Value: [COLOR="Navy"]Next[/COLOR]
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
        Nstr = K: oVal = K
        [COLOR="Navy"]Do[/COLOR] [COLOR="Navy"]While[/COLOR] .exists(oVal)
            Nstr = Nstr & "," & .Item(oVal)
            oVal = .Item(oVal)
        [COLOR="Navy"]Loop[/COLOR]
            c = c + 1
            Cells(c, "D") = StrReverse(Nstr): Nstr = ""
    [COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,094
Latest member
bsb1122

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top