none
Changing Item Colors Based On The Completion Date of The Predecessor RRS feed

  • Question

  • Is there a way that I can have the color of a task change based on the status of the predecessors? For example...

    Item number 3 has a fixed start date, but is dependent upon the completion of its predecessor item number 2. Item number 3 is the color green if the completion date of the predecessor is less than or equal to the start date of item number 3. Item number 3 is the color red if the completion date of the predecessor is greater than the start date of item number 3.

    Is there a way that I set that up in Microsoft Project 2007?

    Thursday, June 11, 2015 9:03 PM

All replies

  • Lee52106,

    Yes this can be done but it will take a little VBA, it can't be done with a formula in a custom field. Why? Because formulas only apply to data in that task line and since you need the format in one task line to be determined by data in another task line, VBA is required.

    I work on the code for you a little later and then post back.

    John

    Update:

    You didn't say if you wanted the field columns colored or the Gantt bars. This code assumes you want the field column colored. Note: if you have change highlighting turned on, and the last edit affected a task you want colored, that task will not be colored, as change highlighting takes precedence.

    Dim t As Task
    Dim td As TaskDependency
    For Each t In ActiveProject.Tasks
        t.Flag1 = False: t.Flag2 = False 'clear flags if set previously
        If Not t Is Nothing Then
            For Each td In t.TaskDependencies
                If td.From.Finish <= t.Start And td.From.UniqueID <> t.UniqueID Then t.Flag1 = True
                If td.From.Finish >= t.Start And td.From.UniqueID <> t.UniqueID Then t.Flag2 = True
            Next td
        End If
    Next t
    FilterEdit Name:="con", taskfilter:=True, create:=True, overwriteexisting:=True, _
        FieldName:="flag1", test:="equals", Value:="yes", ShowInMenu:=False, showsummarytasks:=False
    FilterApply Name:="con"
    SelectAll
    Font32Ex Color:=5287936     'green
    FilterApply Name:="all tasks"
    FilterEdit Name:="con", taskfilter:=True, create:=True, overwriteexisting:=True, _
        FieldName:="flag2", test:="equals", Value:="yes", ShowInMenu:=False, showsummarytasks:=False
    FilterApply Name:="con"
    SelectAll
    Font32Ex Color:=255  'red
    FilterApply Name:="all tasks"
        
    End Sub

    Hope this helps.

    John

    Thursday, June 11, 2015 9:15 PM