In MS Projects, I need to utilize VBA to conditionally format all rows with "payment" somewhere in the Task Name to have bold, red text.
Asked
Active
Viewed 453 times
-1
-
2Your question received an immediate down-vote because it does not meet the guidelines of StackOverflow. Read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and then edit your question to improve it. To get started on writing the code, search stackoverflow for [related questions](https://stackoverflow.com/search?q=%5Bms-project%5Dcolor). Read other [articles about asking questions](https://stackoverflow.com/help/asking). – Rachel Hettinger Oct 04 '22 at 21:32
2 Answers
1
This code should do what you want.
Option Compare Text
Sub BoldRed()
OutlineShowAllTasks
FilterEdit Name:="temp", taskfilter:=True, create:=True, overwriteexisting:=True, FieldName:="Name", test:="contains", _
Value:="payment", ShowInMenu:=False, showsummarytasks:=True
FilterApply Name:="Temp"
SelectTaskColumn Column:="name"
Font32Ex Bold:=True
Font32Ex Color:=255
FilterApply Name:="all tasks"
OrganizerDeleteItem Type:=pjFilters, FileName:=ActiveProject.Name, Name:="temp"
End Sub

E_net4
- 27,810
- 13
- 101
- 139

john-project
- 331
- 1
- 7
-
FYI: Unless you want the payment tasks' parent tasks (eg summary tasks) to also be formatted in red, use `ShowSummaryTasks:=False`. – Rachel Hettinger Oct 05 '22 at 13:00
-
This may be trickier - can I use the code above in an If-Then iteration? I want to change the color if "payment" is present or if "Go-Live" is present or if "Full go-live" is present change cell color, too? – cnpulse Oct 05 '22 at 13:41
-
@RachelHettinger, I am unable to edit my comment to tag you in my If-Then comment; would you please review above and advise? – cnpulse Oct 05 '22 at 14:14
-
@cnpulse To add additional criteria to the filter add this line after the first FilterEdit: `FilterEdit Name:="temp", TaskFilter:=True, FieldName:="", NewFieldName:="Name", test:="contains", Value:="go-live", Operation:="Or", ShowSummaryTasks:=False`. – Rachel Hettinger Oct 05 '22 at 14:59
-
@RachelHettinger - Thank you! Two additional questions - 1) I cannot get the text for the entire row to change color using the SelectRow command before the Font32Ex code; and 2) how do I change the cell background color for rows with specific text to Hex color #FEE599? – cnpulse Oct 05 '22 at 15:29
-
@cnpulse Use `SelectAll` instead of SelectRow to format all text, and use `Font32Ex Color:=255, CellColor:=#FEE599`. – Rachel Hettinger Oct 05 '22 at 16:53
-
@RachelHettinger, I keep receiving a compile error at the # and a different error if I switch it over to RGB values. So I feel like my syntax is incorrect? – cnpulse Oct 05 '22 at 18:12
-
-
@RachelHettinger I am still unable to affect the whole row or change the cell color programmatically. When I am allowed to post again, I will post the entirety of my code for assistance. – cnpulse Oct 05 '22 at 20:37
0
Based on extended comments on prior answer, here is another version of a macro to format the entire row of tasks that contain 'payment' or 'go-live' in the task name.
Sub FormatSpecificTasks()
OutlineShowAllTasks
FilterEdit Name:="temp", TaskFilter:=True, Create:=True _
, OverwriteExisting:=True, FieldName:="Name", Test:="contains" _
, Value:="payment", ShowInMenu:=False, ShowSummaryTasks:=False
FilterEdit Name:="temp", TaskFilter:=True, FieldName:="" _
, NewFieldName:="Name", Test:="contains", Value:="go-live" _
, Operation:="Or", ShowSummaryTasks:=False
FilterApply Name:="temp"
SelectAll
Font32Ex Bold:=True, Color:=255, CellColor:=RGB(255, 229, 99)
FilterApply Name:="all tasks"
OrganizerDeleteItem Type:=pjFilters, FileName:=ActiveProject.Name, Name:="temp"
End Sub

Rachel Hettinger
- 7,927
- 2
- 21
- 31