I would like to make a list of all successors when only given a list with immediate successors and predecessors.

TBeelman

New Member
Joined
Oct 22, 2014
Messages
1
Hello All, I am tasked with a project where I need to solve the impact of constraints. To do this I need to figure out all the tasks that are successors to the tasks that are constrained. I have a list of all the tasks along with their immediate successors and immediate predecessors. I would like to be able to form a list of off successive tasks until the completion. In My example I would like for a shortage in E to tell me that all the successors are D, H, I, J, and K. If I have a shortage in task B I would like to know that tasks F, G, and K are constrained as well. My list has over 3000 operations but they are broken up into 10 groups so around 300 operations per group.(to give you an idea of the size). I need them in a format that I will be able to delete duplicates so I am not counting the same operation twice when I have multiple constraints. Any and all feedback is greatly appreciated. Thanks.
Operation
Successor
Predecessor
A
B
A
C
A
D
B
F
A
B
G
A
E
D
E
H
D
I
A
D
J
E
I
K
D
J
K
D
F
K
B
G
K
B

<tbody>
</tbody>
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi and welcome to the MrExcel Message Board.

You need a recursive type of search. That is, a search that will find the first Successor and then you run the same search again using the Successor as the starting point.

I have assumed that the Operation and Successor are in columns A and B and that the data starts in row 2. I have also assumed that the row in Column A after the data will contain a null character ("").

Code:
Private List As Collection

Function FindSuccessor(ByVal Operation As String)
    If Operation <> "" Then
        On Error Resume Next
        List.Add Operation, CStr(Operation)
        On Error GoTo 0
        i = 2
        Do
            If Cells(i, 1).Value = Operation Then FindSuccessor (Cells(i, 2).Value)
            i = i + 1
        Loop Until Cells(i, 1).Value = ""
    End If
End Function

Sub xx()
    Set List = New Collection
    FindSuccessor ("A")
    For i = 1 To List.Count
        Debug.Print List.Item(i)
    Next
End Sub

As new Successors are found they are added to a Collection. The Collection is keyed so that duplicates are not stored. The "On Error" processing stops errors appearing when duplicates do occur.

Sub xx is the starting point. The above program is starting from "A". It calls FindSuccessor which looks for "A" in column A and finds its Successor in Column B. It then passes "B" to itself and does the same with "B" etc. Each Successor found is stored in the Collection called List.

The loop in xx displays the results.
 
Upvote 0

Forum statistics

Threads
1,217,305
Messages
6,135,731
Members
449,961
Latest member
leobrice

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