Search code examples
vbams-project

Changing a Value in a field using VBA in MS Project


I'm using Text1 field with lookup values in it and based on a specific value from that I want then update the field "Marked" to equal "Yes"

Text1 values - On Target - Delayed

I've tried using formulas within Custom Fields

IIf([Text1]="On Target",[Marked]="True",[Marked]="False")

I'm actually trying to Conditionally format the row when Text1 = Delayed. One reason why I want to do this is to use a field such as [Marked] that is rarely used.


Solution

  • Here's a vba procedure that will set the Marked field depending on the value of the Text1 field.

    Sub SetMarked()
        Dim tsk As Task
        For Each tsk In ActiveProject.Tasks
            If Not tsk Is Nothing Then
                tsk.Marked = (tsk.Text1 = "On Target")
            End If
        Next tsk
    End Sub
    

    FYI: The Flag1-10 fields can be customized with a formula to do the same thing: IIf([Text1]="On Target",True,False). The flag fields can be used to customize the Gantt bars, but not the text in the Gantt table (like the Marked field can).