Simple Macro for Listing Driving Predecessor(s) in MS Project

The Drivers macro reads and copies the ID of each task’s driving predecessors into a custom text field for the task.

One of the missing features for anyone coming to MSP from Primavera’s planning tools is the little mark designating the driving predecessor(s) in the predecessors list for each activity.

MS Project 2010+ kind of addresses this with a feature called “Task Inspector” that opens a pane and displays some scheduling factors affecting the selected task.  One of the factors displayed is the “Predecessor Tasks:” table, which lists the predecessor(s) (if any) that limit the early start date of the selected task.  The driving predecessor is inserted as a link, so it is possible to jump backwards through the driving logic of the schedule.

Since I use BPC Logic Filter, I haven’t had much use for Task Inspector.  Still, it is occasionally useful to see a long list of predecessors and know immediately which ones are driving the selected task.  Here is a little macro to copy the IDs of the driving predecessors into the “Text2” field of each task.

Sub Drivers()

    Dim t As Task
    Dim td As TaskDependency
    Dim PredDr As String
    Dim i As Integer
    
    
    For Each t In ActiveProject.Tasks
        If Not t Is Nothing Then
            PredDr = ""
            i = 0
        
            For Each td In t.StartDriver.PredecessorDrivers
                i = i + 1
                If i = 1 Then
                    PredDr = PredDr & td.From.ID
                Else
                    PredDr = PredDr & "," & td.From.ID
                End If
            Next td
            
            t.Text2 = PredDr
        End If
    Next t

End Sub

The user can then insert the “Text2” column in any task view.  The image at the top of the post is a little schedule with the column inserted as shown and named “Driving Pred”.

The “Drivers” determination is done by MSP’s scheduling engine, and I have found it to be unreliable for driving predecessors that are not Finish-to-Start links.  (Problems with Driving Logic in Task Inspector and Task Paths – Microsoft Project 2010-2016)  Nevertheless, it’s better than nothing.  Obviously, the macro needs to be re-run whenever the logic or task numbering changes….

If you are interested in a real logic trace of the driving path for the activity, then you’ll need a much more sophisticated macro (like this one) or a full-fledged Add-In like BPC Logic Filter – shown in this video.    As a side feature, BPC Logic Filter includes a task Logic Inspector that displays driving and non-driving relationships for any task.  Visit the BPC Logic Filter page to download a fully-functioning Trial version.

 

9 thoughts on “Simple Macro for Listing Driving Predecessor(s) in MS Project”

  1. Thanks a lot for the predecessors macro. – But:
    – when a task has more than one pred. it’s just listing the first
    e.g. 1 -> 2;4 -> 3 Listed is only 2 and 3.

    Tasks without a predecessor aren’t listed.
    E.g. Sequence is: 1 -> 2 -> 3 Listed are only 2 and 3. #1 has no pred. but is important for the list. How to display it?

    1. Eckard,
      I’m afraid you may be misunderstanding the purpose of this macro. Please read the article. In short, the custom text field for each task will list only the driving-flagged immediate predecessor(s) of that task. Your examples imply a different expectation.

  2. Thank-you so much for providing this and the more sophisticated Task Path Filter macro.

    I am trying to present Driving Information to a non-scheduling, inexperienced PM group in a WBS format (using the WBS view in WBS Schedule Pro). Showing networks and Gantt views, I think would make their collective heads hurt. I am using focused views of only their portion of the WBS but the Driving Predecessor ID may be in alternate leg and not shown in the focused display. A pure numerical ID is not useful if they can’t see what it means.

    Would you please re-write this macro to write out both the Driving ID and Driving Task name? I know that Text fields are capped at 255 characters so Task Names may need to be truncated if they are excessive.

    Thanks in advance

  3. RK,
    You could edit the macro yourself by changing
    td.From.ID
    to
    td.From.ID & ” ” & td.From.Name
    each place it occurs.

    1. Thank you Tom.

      My VBA skills are sorely lacking even though I guessed it would be something simple.

      Cheers
      Bob

  4. Thanks to further help from Tom and some more careful typing by me, I was able to get the Macro doing what I wanted.

    Thanks again, Tom

    Bob

  5. For PredecessorDrivers I noticed something off (in my results). Looking at Microsoft’s documentation it had this tidbit:
    “If TotalDetectedCount is greater than 5 then count is 0.”
    URL: https://learn.microsoft.com/en-us/office/vba/api/project.predecessordrivers.count

    In those instances, greater than 5, I noticed that Microsoft also doesn’t bother to populate the TaskDependency array that you use here:
    “For Each td In”

    Am I alone in finding this to be troubling?

    Thanks!
    Phil

    1. Interesting…. I’ve confirmed this behavior goes back to Project 2016. I.e. if there are more than 5 direct predecessors that are equally driving, then the array to hold those predecessor relationships is not populated.

      Phil D,
      In general I don’t think this affects the schedule calculations (like dates and slack) at all, so I’m not especially bothered. The primary use case for the array seems to be Project’s Task Inspector pane: if there are 5 or fewer predecessor drivers, then the TI pane lists them with a direct-jump link to each. More than five and TI drops back to “This task is being driven by xxx predecessors.” (where xxx is the TotalDetectedCount). That’s probably a decision driven by display space. The TaskPath driving predecessors fields don’t seem to be similarly constrained.

      In logic driven schedules, tasks with more than five predecessors are uncommon; one with more than five predecessors that are equally driving is a rare bird indeed.

Leave a Reply

Your email address will not be published. Required fields are marked *