none
Predecessors Full chain list RRS feed

  • Question

  • Hi, 

    I am looking for VBA to help me to extract the full chain list of predecessors.

    For example: Task #5 has Tasks #51 and #60 as predecessors.

    Task #51 has tasks #90 and #100 as predecessors.

    I am looking for a way to give me the full chain of predecessors of task #5 in my example

    Appreciate your help 

    Ofekim 

    Sunday, July 22, 2012 9:53 AM

Answers

  • Hi Ofekim,

    great tip of Project User to use Jack Dahlgren's macro.

    Some time ago, I had a similar request of a customer: They wanted to see the complete chain of predecessors in field Text1. Perhaps this gives you an additional idea? If you are not located in Europe, I assume you will have to replace ';' by ','.

    Sub Dep_Chain()
    Dim t As Task
    For Each t In ActiveProject.Tasks
        If Not t Is Nothing And t.Predecessors <> "" Then
            t.Text1 = Left(Dep_Recursive(t), Len(Dep_Recursive(t)) - 1)
            MyArray = Split(t.Text1, ";")
            MyArray_count = UBound(MyArray)
            SortArray MyArray
            If UBound(MyArray) > 0 Then
            For j = 0 To UBound(MyArray)
                If j = 0 Then
                    t.Text1 = CStr(MyArray(j))
                ElseIf CStr(MyArray(j - 1)) <> CStr(MyArray(j)) Then
                    t.Text1 = t.Text1 & ";" & CStr(MyArray(j))
                End If
            Next j
            End If
        End If
    Next t
    End Sub
    Public Function SortArray(TheArray)
    Sorted = False
    Do While Not Sorted
        Sorted = True
    For k = 0 To UBound(TheArray) - 1
        If TheArray(k) > TheArray(k + 1) Then
            Temp = TheArray(k + 1)
            TheArray(k + 1) = TheArray(k)
            TheArray(k) = Temp
            Sorted = False
        End If
    Next k
    Loop
    End Function
    
    Function Dep_Recursive(t)
        T_Pre = Split(t.Predecessors, ";")
        T_Pre_C = UBound(T_Pre)
        For i = 0 To T_Pre_C
        Dep_Recursive = Dep_Recursive & ActiveProject.Tasks(CInt(T_Pre(i))) & ";" & Dep_Recursive(ActiveProject.Tasks(CInt(T_Pre(i))))
        Next i
    End Function
    Good luck!
    Barbara
    Sunday, July 22, 2012 1:42 PM
    Moderator

All replies

  • Pls check the trace macro here

    For immediate predecessors, just apply a combination view where Gantt Chart view is on the top and Task Form view with Predecessors & Successors detail (use the right-click shortcut menu on the view to apply different details) on the bottom, and then select a task on the top pane to see all the predecessors on the bottom pane.


    Sunday, July 22, 2012 12:21 PM
  • Hi Ofekim,

    great tip of Project User to use Jack Dahlgren's macro.

    Some time ago, I had a similar request of a customer: They wanted to see the complete chain of predecessors in field Text1. Perhaps this gives you an additional idea? If you are not located in Europe, I assume you will have to replace ';' by ','.

    Sub Dep_Chain()
    Dim t As Task
    For Each t In ActiveProject.Tasks
        If Not t Is Nothing And t.Predecessors <> "" Then
            t.Text1 = Left(Dep_Recursive(t), Len(Dep_Recursive(t)) - 1)
            MyArray = Split(t.Text1, ";")
            MyArray_count = UBound(MyArray)
            SortArray MyArray
            If UBound(MyArray) > 0 Then
            For j = 0 To UBound(MyArray)
                If j = 0 Then
                    t.Text1 = CStr(MyArray(j))
                ElseIf CStr(MyArray(j - 1)) <> CStr(MyArray(j)) Then
                    t.Text1 = t.Text1 & ";" & CStr(MyArray(j))
                End If
            Next j
            End If
        End If
    Next t
    End Sub
    Public Function SortArray(TheArray)
    Sorted = False
    Do While Not Sorted
        Sorted = True
    For k = 0 To UBound(TheArray) - 1
        If TheArray(k) > TheArray(k + 1) Then
            Temp = TheArray(k + 1)
            TheArray(k + 1) = TheArray(k)
            TheArray(k) = Temp
            Sorted = False
        End If
    Next k
    Loop
    End Function
    
    Function Dep_Recursive(t)
        T_Pre = Split(t.Predecessors, ";")
        T_Pre_C = UBound(T_Pre)
        For i = 0 To T_Pre_C
        Dep_Recursive = Dep_Recursive & ActiveProject.Tasks(CInt(T_Pre(i))) & ";" & Dep_Recursive(ActiveProject.Tasks(CInt(T_Pre(i))))
        Next i
    End Function
    Good luck!
    Barbara
    Sunday, July 22, 2012 1:42 PM
    Moderator
  • Just a note ---

    In Project 2013 Preview, we can highlight all the predecessors of a task using the new Task Path feature in a Gantt Chart view. The button is placed in Format tab of the ribbon.

    Regards.


    Wednesday, July 25, 2012 12:00 PM