none
Task indicator. All Predecessor tasks are complete y/n, true/false RRS feed

  • Question

  • I would be most grateful if someone could provide a complete solution that would allow me to create a task field that would indicate if all predecessor tasks are complete or not.   This would allow me to do some desperately needed filtering.  MS-Project 2010.

    Thanks in advance,

    J

    Wednesday, October 10, 2012 2:59 AM

Answers

  • Hello J,

    The code below will set flag7 to true if there are no incomplete predecessors, and flase if any incomplete predecessors are found:

    Sub GetPredStatus() Dim pj As Project Dim t As task 'subject task Dim p As task 'Predecessor task

    Set pj = activeProject

    For Each t In activeProject.Tasks If t Is Nothing Then GoTo NextTask For Each p In t.PredecessorTasks If p.percentComplete < 100 Then t.Flag7 = False GoTo NextTask End If Next p t.Flag7 = True NextTask: Next t End Sub



    • Edited by Andrew Simpson Wednesday, October 10, 2012 8:55 AM
    • Proposed as answer by Andrew Simpson Thursday, October 11, 2012 3:16 PM
    • Marked as answer by JayDove78 Saturday, October 20, 2012 5:45 PM
    Wednesday, October 10, 2012 8:35 AM

All replies

  • Hello J,

    The code below will set flag7 to true if there are no incomplete predecessors, and flase if any incomplete predecessors are found:

    Sub GetPredStatus() Dim pj As Project Dim t As task 'subject task Dim p As task 'Predecessor task

    Set pj = activeProject

    For Each t In activeProject.Tasks If t Is Nothing Then GoTo NextTask For Each p In t.PredecessorTasks If p.percentComplete < 100 Then t.Flag7 = False GoTo NextTask End If Next p t.Flag7 = True NextTask: Next t End Sub



    • Edited by Andrew Simpson Wednesday, October 10, 2012 8:55 AM
    • Proposed as answer by Andrew Simpson Thursday, October 11, 2012 3:16 PM
    • Marked as answer by JayDove78 Saturday, October 20, 2012 5:45 PM
    Wednesday, October 10, 2012 8:35 AM
  • This is terrific.  Thanks so much.  A few follow-up questions...

    Will this macro go through all tasks in the project and set an indicator for each task (to indicate if all predecessor tasks related to the task are complete or not)?

    Will the indicator be based on all predecessor tasks regardless where the predecessor task resides in the project plan?

    Thursday, October 11, 2012 12:32 AM
  • Andrew,

    Using "GoTo" is a little archaic. Instead you could simply say "Exit For" to jump out of the inner loop once you found a predecessor that is not complete.

    To avoid blank rows, (although I don't think you can even have a blank task row in Project 2010), the shorter version is:

    "If Not t is Nothing Then"

    John

    Thursday, October 11, 2012 2:06 AM
  • Thanks John,

    "Exit For" isn't something I've used before, but I can see the logic in it, thanks for the tip.

    Wouldn't work in this case though as I needed to exit the for/next loop and skip the t.flag7 = true statement immediately after the loop.

    Good tip on the if statement too, thanks again.

    Thursday, October 11, 2012 8:38 AM
  • Hi Jay

    >>Will this macro go through all tasks in the project and set an indicator for each task (to indicate if all predecessor tasks related to the task are complete or not)?

    Yes

    >>Will the indicator be based on all predecessor tasks regardless where the predecessor task resides in the project plan?

    Yes

    Thanks,

    Andrew

    Thursday, October 11, 2012 8:39 AM
  • Andrew,

    You're welcome. With regard to setting the flag to true, I normally set a variable, in this case Flag7 to my desired state before I enter a loop. Then if the loop criteria is met, the flag is set to false. So yes, you can use the Exit For.

    On the other hand you could also restructure the code based on the fact that by default, all extra flag fields are false. Then you would reverse the logic and set the flag true if all predecessors are 100%.

    Just another thought.

    John

    Friday, October 12, 2012 2:54 AM
  • Andrew,

    Thank you for your time.   This was very helpful.  I can't imagine I'm the only person that finds this useful.  I wonder if a similar indicator will ever be included a future release.

    Thanks again,

    J

    Saturday, October 20, 2012 5:47 PM
  • yeah I see where you are coming from on the inner-most Goto since you want to kick out of the Precdecssor loop as soon as you find ANY predecessor that is not complete.

    As for the first one it is just a matter of preference.

    I tend to go for this basic loop structure for all task and resource collection loops:

    For each T in Activeproject.Tasks

      If NOT (T is Nothing) then

      End if

    Next T


    Brian Kennemer - Project MVP
    DeltaBahn Senior Architect
    endlessly obsessing about Project Server…so that you don’t have to.
    Blog | Twitter | LinkedIn

    Saturday, October 20, 2012 7:10 PM
    Moderator
  • Hello Mr Kennemer

    I realise this post is very old now, but do you have similar code for Project 2013?

    This is amazingly useful for those quite new to project managing when they are moving on to bigger projects!

    Thanks so much.

    Best Wishes

    Mike

    Monday, November 13, 2017 6:03 PM
  • Mike,

    I'm not sure if Brian is still watching this forum any more so let me answer you question.

    Macro code is pretty transparent among all versions of Project. The only issues that normally pop up is if a macro that was written using methods or properties not available in older versions and then that macro is run under the older version, failures will occur. The original code written by Andrew and re-structured by Brian do not fall into that category. In fact, this macro should run on any version of Project from Project 98 up through Project 2016.

    hope this helps.

    John

    Monday, November 13, 2017 9:07 PM
  • Hello,

    This formmula will help me very much.

    I have an additional question.

    What do i have to change in the formula to when in dont´whant to look at all predecessor task, but especially to one resourcegroup.

    So if the predecessor of a resourcegroup are 100%, the flag will be true?

    Thanks in advance,

     

    Sunday, January 5, 2020 10:03 AM
  • Willem,

    How are your resource groups identified?

    Task relationships (i.e. predecessors and successors) are associated with a task, not a resource, so there is no "predecessor of a resource group". However, if your tasks are set up such that each task is performed by resources that are only associated with a single group, then the code can be modified to look for that particular group. For example, let's say you have 3 resource groups (plumbers, electricians and framers) and each of those groups has 2 resources. If a task requires both framers and plumbers then you can't segregate the predecessors of that task with a single resource group. But if only plumbers are assigned to certain tasks, electricians assigned to other tasks and framers assigned to their own tasks, then the code can be modified.

    John

    Sunday, January 5, 2020 4:15 PM