Tag Archives | Context Sensitive Task Bar Colours

Project Context Sensitive Task Bar Colours

Is it possible to have task bars in Microsoft Project that change colour depending upon the value in a custom field? An interesting question I thought when this was posed to me. I am going to show you how to create a custom field and then how to have tasks bars change colour automatically depending upon the value in the field.

Creating a Custom Text Field

To create a custom field, right-click on any of the existing column titles in the Gantt Chart grid and choose Custom Fields from the pop-up menu.

CustomFieldIn the top-right drop-down selector choose Text if you want the field to store multiple values.

Now click on the first available field in the list – here Text1 is selected – and then click on the Rename… button. Give the field a suitable name.

Having now created the custom field, right-click on the column title where you want to display your new field and select Insert Field from the pop-up menu. Scroll down the list of field names and select your new field (as you renamed a Text field it will still appear with all the other default text fields in the listing – not an alphabetical listing).

The field can now be used to enter whatever text you wish.

Creating Custom Flag Fields

We can set up Task Bar Styles that will change colour automatically; however, this only works when the field that the style reacts to is a Flag field (which represents Yes/No values). Therefore, to get this to work with Text fields we need to introduce some Flag fields that interact with the Text fields. Follow this example.

Create a custom Text field and rename it DemoState. Insert it into your project columns somewhere. In the DemoState column enter random values using A or B or C.  Because Task Bar Styles will only change colour automatically on Yes/No flag fields, we need to create additional custom Flag fields. The rule is for each possible value in your custom Text field you want to highlight with a different task bak colour you need to create an additional custom Flag field. So let’s say that whenever I have B in my DemoState field I want it to show Red in the task bar, and whenever I have C in my DemoState field I want it to show as a green task bar; A in the field can stay the default blue colour.  As I want two special colours I need two additional custom Flag fields. CustomFlag

So follow the instructions above to create a custom field but this time in the displayed dialog, select Flag in the top-right drop-down selector. The first custom Flag field I will rename as IsItB. The additional selection in the same dialog for this Flag field is to select the Custom attribute of Formula (click on the Formula button).

We now use the IIF function to determine if the value of B is set in my DemoState field. The IIF function uses the following syntax

IIF(Condition Test, Value if True, Value if False)

IsIt_BTherefore, our formula will be:

IIF([Text1]="B", Yes, No)

It is important to note that the formula refers to the original Text1 field name not our renamed DemoState.

Having created this custom field, I will repeat this with another custom Flag field and call it IsItC and the formula in this one will be :

IIF([Text1]="C", Yes, No)

Now I have created the two custom flag fields, I do not need to display them in the Gantt chart columns.

Creating Custom Bar Styles

The final step is to create the different Task Bar colour styles. In BarStylesthe Ribbon’s Gantt Chart tools Format tab, in the Bar Styles group, click on the Format button and choose Bar Styles in the drop-down menu. Scroll to the bottom of the list and add a new entry. I will name my entry as B Colour (in the first column Name). As soon as you have typed the new name and moved to the next column a default pattern and colour is set. Using the Bars tab in the bottom-half of this dialog, select a solid Pattern in the Middle section and then change the Color setting in the Middle section to Red. Back in the top half, in the third column (Show for …Tasks) for the this new style select the Flag1 field (as before we are using the default field name not our renamed IsItB.)

Repeat the style creation but this time calling it C Colour using Green as the colour and Showing for Flag 2.


In summary, we need to create our custom text field to hold our different values. For each value that you want to have a different task bar colour, then create a custom Flag field that uses the IIF function to display Yes if the text field holds the value you want to change the task bar colour for. Finally, create a Bar Style for each colour you want and assign it to show for your Flag field.

A somewhat convoluted process but it does work.