Filter Predecessors in Microsoft Project
If you’re working with complex .mpp files and thousands of interconnected tasks spread across multiple owners, analyzing dependencies can be a real challenge.
Or perhaps your client—or even colleagues in your organization—aren’t comfortable using Microsoft Project to investigate dependencies themselves but still need to understand which tasks (e.g., your milestones’ predecessors or successors) are critical.
Since I face this situation daily, I needed an efficient way to handle it. After experimenting with several approaches, I landed on a simple yet effective solution: a VB macro that streamlines this task.
When to Use It
Imagine you’re working on a project where multiple entities contribute to the same plan, with tasks scattered throughout. Things can get especially messy when task names are repeated across environments, such as Dev, Test, Stage, or Prod.
If you enforce a clear naming convention (e.g., “VM Build - DC1 - DEV,” where no two tasks in the plan share the same name), you can often rely on Microsoft Project’s built-in Task Inspector. However, when naming conventions are inconsistent, beyond your control, or repeating as in the example below, this macro is a game-changer.
How to Add the Macro
1. Navigate to View > Macros > Visual Basic (or use the shortcut Alt + F11).
2. In the Visual Basic editor, go to Insert > Module to create a new module.
3. Copy and paste the script into the module, then save it.
• (Optional) If you also want to add the clean-up macro, repeat steps 2 and 3 for the second script.
4. Close the Visual Basic editor.
Mark Predecessors Code
Sub MarkPredecessors()
' Get the list of predecessor task IDs from the user
Dim userInput As String
userInput = InputBox("Enter the list of predecessor task IDs (semicolon-separated):", "Predecessor List")
' Check if the user entered any input
If Len(Trim(userInput)) = 0 Then
MsgBox "No input provided. Exiting script."
Exit Sub
End If
' Split the user input into an array
Dim predecessorArray() As String
predecessorArray = Split(userInput, ";")
' Iterate through tasks and mark those with specified predecessors
For Each Task In ActiveProject.Tasks
Dim taskID As String
taskID = CStr(Task.ID)
' Check if the task has a predecessor in the specified list
If InStr(1, ";" & userInput & ";", ";" & taskID & ";") > 0 Then
Task.Text13 = "X"
End If
Next Task
' Inform the user that the marking has been applied
MsgBox "Marking applied for the specified predecessor tasks."
End Sub
Clear Text 13 Code
Sub ClearText13Column()
' Clear the values in the "Text13" column for all tasks
For Each Task In ActiveProject.Tasks
Task.Text13 = ""
Next Task
' Inform the user that the column has been cleared
MsgBox "Values in Text13 column cleared for all tasks."
End Sub
Workflow
1. In Microsoft Project, add a new column named Text13.
2. Identify the Predecessors or Successors of the task you want to analyze and copy them. I recommend using Notepad or OneNote as an interim storage place to clean up the list, especially to remove lags/leads.
• Example:
Milestone 1: 115;289;325;416;2893;2943;2948;3005;3641;6219FS+15 days;6442
Note that the entry 6219FS+15 days includes a lag, which the script cannot handle. You’ll need to remove the lag and only keep the task ID (6219).
3. Clear any active filters in your project unless you’re sure they’re aligned with your analysis. The script doesn’t modify existing filters, so incomplete task filters, for example, will remain active.
4. Copy the cleaned task list from your interim storage.
5. Run the macro:
• Go to View > Macros > View Macros, select the MarkPredecessors macro, and run it. (Alternatively, use Alt + F8 to access the macro list.)
• Paste the cleaned task list into the pop-up window and click OK.
6. The macro will mark tasks by inserting an “X” in the Text13 column. Once complete, you’ll receive a notification.
7. Filter out blank values in the Text13 column to isolate the marked tasks.
8. When you’re done, clean up the Text13 column manually or run the ClearText13Column macro to remove the markings. If you forget to clean the column, the “X” values will persist and might interfere with future analyses.
Customizing the Script
You can easily modify the script to suit your workflow.
Change the Delimiter
Replace all “;” in the script with your preferred delimiter (e.g. “,”).
Update the prompt text if needed by replacing "Enter the list of predecessor task IDs (semicolon-separated):" with your preferred prompt.
Change the Text13 Column
If you prefer using a different column:
• Replace Task.Text13 with your desired column (e.g., Task.Text5).
• Update both the marking and clean-up macros accordingly.
Remove the Confirmation Prompt
If you don’t want the script to notify you when it finishes, remove or comment out this line: MsgBox "Marking applied for the specified predecessor tasks."
Combine Marking and Clean-Up Scripts
If you prefer to clear the Text13 column before running the MarkPredecessors macro:
• Copy the clean-up script (excluding the first and last lines of code).
• Paste it as the second line in the MarkPredecessors script.
While I prefer keeping the macros separate, combining them may better suit your workflow.
Why This Approach?
There are alternative ways to achieve similar results in Microsoft Project, such as using custom views. However, this method offers quick toggling via the Text13 column, making it more versatile and efficient for many scenarios.
Additional Use Cases
This script isn’t limited to dependency (predecessors/successors) filtering. It can also be used for:
• Impact Assessment: Analyze how delays in a task might affect successors.
• Scenario Planning: Isolate dependencies for a task or phase to simulate schedule changes.
• Stakeholder Alignment: Share filtered task lists for specific milestones or project phases.
• Testing and Validation: Filter tasks during testing to ensure all dependencies are met before proceeding.
• Supply Chain Management: Identify tasks or shipments reliant on earlier steps in the chain.
• Portfolio Dependency Mapping: Extend the script to track dependencies across multiple projects.
• Prioritization of Cross-Project Tasks: Focus on tasks that are prerequisites or successors for multiple initiatives.
• Change Impact Analysis: Assess how changes in one project might ripple through others.
I’d love to hear about other methods you use for this type of filtering or any additional use cases you’ve discovered.