A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Discussion (Misc queries)
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Finding loops in parent/child relationships



 
 
Thread Tools Display Modes
  #1  
Old November 21st 07, 05:34 PM posted to microsoft.public.excel.misc
GrahamC
external usenet poster
 
Posts: 4
Default Finding loops in parent/child relationships

Hi,
I'm hoping someone can help me with a thorny problem.

I have a worksheet with 2 columns of data: 1 called Parent and the other
called Child. A number represents each 'person' and each row represents a
parent/child relationship e.g.

Parent Child
1 2
2 3
3 4
4 5
4 2
5 8
6 7
7 8
8 1

I am trying to find the rows that cause a loop in the parent/child hierarchy
i.e. a child eventually has one of its parents as its own child.

I've tried using VLOOKUP to build a lineage of grandparents, great
grandparents etc but that doesn't cope with the case where a child has more
than one parent.

Please could someone help? Have you solved this kind of problem before?

Thanks in advance,
Graham
Ads
  #2  
Old November 21st 07, 05:43 PM posted to microsoft.public.excel.misc
Gary''s Student
external usenet poster
 
Posts: 11,059
Default Finding loops in parent/child relationships

Easy to do in VBA. Build a lineage string one record at a time. Each time
an element is added, a check is made to insure the element has not already
been added:
1->2
1->2->3
1->2->3->4
1->2->3->4->5

The next step fails...Although 4 can have many children, it can't have #2
because #2 is already on the list. Let us know if a VBA solution is O.K.

--
Gary''s Student - gsnu200758


"GrahamC" wrote:

> Hi,
> I'm hoping someone can help me with a thorny problem.
>
> I have a worksheet with 2 columns of data: 1 called Parent and the other
> called Child. A number represents each 'person' and each row represents a
> parent/child relationship e.g.
>
> Parent Child
> 1 2
> 2 3
> 3 4
> 4 5
> 4 2
> 5 8
> 6 7
> 7 8
> 8 1
>
> I am trying to find the rows that cause a loop in the parent/child hierarchy
> i.e. a child eventually has one of its parents as its own child.
>
> I've tried using VLOOKUP to build a lineage of grandparents, great
> grandparents etc but that doesn't cope with the case where a child has more
> than one parent.
>
> Please could someone help? Have you solved this kind of problem before?
>
> Thanks in advance,
> Graham

  #3  
Old November 22nd 07, 11:10 AM posted to microsoft.public.excel.misc
GrahamC
external usenet poster
 
Posts: 4
Default Finding loops in parent/child relationships

Thanks. Looks like I will have to learn VBA! Is there no other way using
Excel functions?

Regards,
Graham

"Gary''s Student" wrote:

> Easy to do in VBA. Build a lineage string one record at a time. Each time
> an element is added, a check is made to insure the element has not already
> been added:
> 1->2
> 1->2->3
> 1->2->3->4
> 1->2->3->4->5
>
> The next step fails...Although 4 can have many children, it can't have #2
> because #2 is already on the list. Let us know if a VBA solution is O.K.
>
> --
> Gary''s Student - gsnu200758
>
>
> "GrahamC" wrote:
>
> > Hi,
> > I'm hoping someone can help me with a thorny problem.
> >
> > I have a worksheet with 2 columns of data: 1 called Parent and the other
> > called Child. A number represents each 'person' and each row represents a
> > parent/child relationship e.g.
> >
> > Parent Child
> > 1 2
> > 2 3
> > 3 4
> > 4 5
> > 4 2
> > 5 8
> > 6 7
> > 7 8
> > 8 1
> >
> > I am trying to find the rows that cause a loop in the parent/child hierarchy
> > i.e. a child eventually has one of its parents as its own child.
> >
> > I've tried using VLOOKUP to build a lineage of grandparents, great
> > grandparents etc but that doesn't cope with the case where a child has more
> > than one parent.
> >
> > Please could someone help? Have you solved this kind of problem before?
> >
> > Thanks in advance,
> > Graham

  #4  
Old November 22nd 07, 05:15 PM posted to microsoft.public.excel.misc
Gary''s Student
external usenet poster
 
Posts: 11,059
Default Finding loops in parent/child relationships

I don't see an alternative.
--
Gary''s Student - gsnu200758


"GrahamC" wrote:

> Thanks. Looks like I will have to learn VBA! Is there no other way using
> Excel functions?
>
> Regards,
> Graham
>
> "Gary''s Student" wrote:
>
> > Easy to do in VBA. Build a lineage string one record at a time. Each time
> > an element is added, a check is made to insure the element has not already
> > been added:
> > 1->2
> > 1->2->3
> > 1->2->3->4
> > 1->2->3->4->5
> >
> > The next step fails...Although 4 can have many children, it can't have #2
> > because #2 is already on the list. Let us know if a VBA solution is O.K.
> >
> > --
> > Gary''s Student - gsnu200758
> >
> >
> > "GrahamC" wrote:
> >
> > > Hi,
> > > I'm hoping someone can help me with a thorny problem.
> > >
> > > I have a worksheet with 2 columns of data: 1 called Parent and the other
> > > called Child. A number represents each 'person' and each row represents a
> > > parent/child relationship e.g.
> > >
> > > Parent Child
> > > 1 2
> > > 2 3
> > > 3 4
> > > 4 5
> > > 4 2
> > > 5 8
> > > 6 7
> > > 7 8
> > > 8 1
> > >
> > > I am trying to find the rows that cause a loop in the parent/child hierarchy
> > > i.e. a child eventually has one of its parents as its own child.
> > >
> > > I've tried using VLOOKUP to build a lineage of grandparents, great
> > > grandparents etc but that doesn't cope with the case where a child has more
> > > than one parent.
> > >
> > > Please could someone help? Have you solved this kind of problem before?
> > >
> > > Thanks in advance,
> > > Graham

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
finding multiple parent-child relationships? Keith R Excel Worksheet Functions 4 April 16th 07 04:13 PM
Retrieving info from "child" to a "parent" document create button to unhide rows Excel Discussion (Misc queries) 0 January 21st 07 10:40 PM
Windows browser Parent/Child structure ERK New Users to Excel 2 December 3rd 06 12:44 AM
Relationships / Calculations shone Excel Discussion (Misc queries) 4 June 6th 06 07:51 PM
Sorting Parent Child kcmtnbiker Excel Worksheet Functions 2 March 31st 06 01:54 AM


All times are GMT +1. The time now is 12:28 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 ExcelBanter.
The comments are property of their posters.