Visual Basic MS Project cell formatting question

K, James 1 Reputation point
2021-03-02T19:16:04.36+00:00

Hello,

I have built a MS Project file that tracks the task status (i.e. in progress, done, not started, etc) and resource name associated with each task. I currently have a script that scans the entire active project and looks for the task status and colors the cell based on the status (i.e. if in progress --> color light green) and it also scans the entire active project and looks for the resource name and colors the cell a different color based on the name.

What I would like to do is write a script that looks at the value in the task status and checks the value, and if value equals done, ignore coloring that task cell AS WELL AS ignore coloring the resource name cell (sample of what I am looking for below obviously without the correct syntax since i am still a beginner at visual basic).

if not task status = done then <-- main loop
if task status = in progress then <-- sub if 1
color task status cell lightgreen
if resource name = James then <-- sub if 1 sub
color resource name cell blue
end if
end if

if task status = not started then <-- sub if 2
color task status cell orange
if resource name = James then <-- sub if 2 sub
color resource name cell blue
end if
end if
end if

Here is a copy of the code that I wrote (based on recording a macro and figuring out what I did). I have multiple of this in my code to search for different text so would be nice to be able to shrink the code length down as well.

Dim t2 As Task
Dim i2 As Integer
i2 = 1
For Each t2 In ActiveProject.Tasks

SelectRow row:=i2, RowRelative:=False

If Not t2 Is Nothing Then
    Find Field:="Text4", Test:="equals", Value:="Not Started"
    Font32Ex Size:="12", CellColor:=11324407 'LightOrange
End If
i2 = i2 + 1
Next t2
{count} votes