Show only successors to a selected task in Microsoft Project

I’ve frequently wanted to quickly show all the tasks which are dependant on another from within Microsoft Project but have never found a quick was and easy way using stock the tools.

The following is a snippet of Visual Basic code which will create and apply a new filter, only displaying tasks which are dependant on a selected task.

To use it, add the Code to a Module, pick a free “custom flag field” by changing the second 2 lines (defaults to 20), create a button on the Interface for the new macro, select the task you want to analyse and click the button. Only tasks which have a traceable predecessor relationship to the selected task will be shown.

You will need to run the macro again if you want to view another task, so the filter is re-created.

Sub FilterSuccessor()
    ' Configure what you want the Filter to be called
    Dim filterName As String: filterName = "Rob's - Successors to selected Task"
    ' Configure the Flag Field we'll use to apply the filter (both should be the same number)
    Dim flagName As String: flagName = "Flag20"
    Dim flagType As PjField: flagType = pjTaskFlag20
    Dim t As Task
    For Each t In ActiveProject.Tasks
        If Not t Is Nothing Then
            t.SetField flagType, "No"
        End If
    Next t
    For Each t In ActiveSelection.Tasks
        SetSuccessorFlag flagType, t
    Next t
    FilterEdit Name:=filterName, TaskFilter:=True, _
        Create:=True, OverwriteExisting:=True, FieldName:=flagName, _
        Test:="equals", Value:="Yes", ShowInMenu:=False, ShowSummaryTasks:=True
    FilterApply Name:=filterName
End Sub
Private Function SetSuccessorFlag(flagField As PjField, tIn As Task)
    If Not tIn Is Nothing Then
        ' Flag this Task
        tIn.SetField flagField, "Yes"
        Dim t As Task
        For Each t In tIn.SuccessorTasks
            ' Flag it's successors
            t.SetField flagField, "Yes"
            ' Flag it's successor's sucessors
            SetSuccessorFlag flagField, t
        Next t
    End If
End Function

Edit: Thanks to Mike Walker for trying the previous code and sending me his file to test; turns out MSProject has a limit of 40 conditions when applying filters. The code has been updated so it should work with any number of identified successors.

Leave a Reply

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