Excel Conditional Formatting (PC)
Excel Conditional Formatting (PC)
Excel Conditional
Formatting
Using colour to make data analysis easier
Excel conditional formatting automatically formats cells in your It’s good to have
worksheet if specified criteria are met, giving you a visual aid for an understanding
analysing your data. of Excel formulae
and functions in
These workshop notes are suitable for Excel 2016, 2013 and Excel before
2010, although some of the techniques are not available in Excel working through
2010. this document.
Last updated
by Faye Brockwell
28 August 2018
This document and other Excel documents are held online on our website:
https://staff.brighton.ac.uk/is/training/Pages/Excel/Excel.aspx
University of Brighton Information Services
Contents
Introduction ...................................................................................................... 3
Predefined conditional formatting ..................................................................... 3
Exercise A. Highlighting cells .................................................................... 4
Exercise B. Top and Bottom Rules ........................................................... 4
Introduction
Excel conditional formatting automatically formats cells in your worksheet if specified
criteria are met. For example, you can:
Change the text of a cell to red if a project has gone over budget
Add an icon to highlight any figures that were an improvement on this time last
year.
Select the area in your worksheet to which you want to apply conditional
formatting.
Choose the type of conditional formatting you want from the list.
Select the area in your worksheet to which you want to apply conditional
formatting.
Click on the Quick Analysis icon that appears at the bottom right of the
selection.
Page | 3
University of Brighton Information Services
The following exercises suggest some applications for some of the pre-defined
conditional formats.
5. Click on Between.
Click on Clear Rules from selected cells (or click on Clear Rules from Entire
Sheet if you want to get rid of all rules in the worksheet).
Click on the Quick Analysis icon that appears at the bottom right of the
selection.
Page | 5
University of Brighton Information Services
Data bars and Colour Scales are also available via the Quick Analysis icon
in Excel 2013 and 2016, although the colour selection is limited.
Icon sets are also available via the Quick Analysis icon in Excel 2013 and
2016, although the icon selection is limited.
Page | 7
University of Brighton Information Services
Select the cells that you want to apply the conditional formatting to.
Click OK.
Rules manager
The rules manager is a really simple way of being able to get a handle on all of
the conditional formatting you have in a workbook. As your spreadsheets
become more complex you’ll need to make sure you know where to quickly
reference all of the formatting rules you have setup and what data they may be
affecting.
To access the Rules Manager:
Click the Manage Rules… option from the drop down menu
View all rules in your workbook, individual worksheets or even just the selected
cells
Create new rules using the pre-existing templates or by using formulas and
statements
Page | 9
University of Brighton Information Services
o Build the formula for one cell – you can then apply
the formula to other cells
o Use $ signs to control how cell references behave
when the formula is applied to other cells
o Don’t use arrow keys to move your cursor within the
formula as this will change your cell references.
Click on Format to choose how to format the cells if the condition is true
Click OK.
You have defined your rule. Now you need to specify the cells to which that rule
will apply.
Page | 11
University of Brighton Information Services
1. Open up the file Ghostbusters.xls and click on the Simple Rule tab.
This spreadsheet shows the number of ghosts busted by each member of staff
on our ghostbusting team. We are going to create a rule that highlights in red any
months where our target has not been met.
Note that this rule could also be set up using predefined conditional formatting
rules, but we’re using it as a simple example to explain how to set up your own
rule.
3. Open up the Conditional Formatting Rules Manager and show all rules for this
worksheet.
4. Click on New Rule and click to choose Use a formula to determine which
cells to format
This will add dollar signs to the cell reference for the target number of ghosts
busted. Without making this cell reference absolute using the dollar signs, when
we apply the conditional formatting rule to other cells in the worksheet, this cell
reference will be changed in relation to where the new cells are, which will affect
the result of the formula.
For more information on Absolute Referencing, see the Exercise F which gives a
refresher on absolute referencing.
8. Click on the Format button, choose to fill the cells with red and click OK.
9. Click OK.
10. In the rules manager, click on the icon for our new rule to specify the range of
cells to which we want to apply this rule.
11. On the worksheet itself, use your mouse to select the cell range E2 to G7. Then
click to expand the Rules Manager again.
2. This file shows the prices for a list of products and the surcharges and discounts
applied.
3. Build a formula in cell C11 to calculate the surcharge for that row =B11*B5
6. Press Esc and then double click on cell C12. The boxes
show the cell references. These surcharge cell
reference is incorrect. Instead of pointing to cell B5, the
cell reference has changed to B6. This is because the
cell reference is relative, Excel adds 1 to any row
number in a formula when that formula is copied down a
column.
7. Press Esc and then double click on cell C13. The boxes
show the cell references. The surcharge cell reference
is incorrect. Instead of pointing to cell B5, the cell
reference has changed to B7. This is because the cell
reference is relative, Excel adds 1 to any row number in
a formula when that formula is copied down a column.
Page | 13
University of Brighton Information Services
This is what has happened to our formula as it was copied down column C:
Cell Formula
C12 =B12*B6
C13 =B13*B7
We want the first cell reference to increment by 1 for each row, but we always want
our formula to refer to cell B5 for the surcharge regardless of the current row. To
do this, we must make the cell reference absolute.
9. Click your insertion point so that it is flashing on the B5 cell reference in your
formula.
10. Press the F4 key. This will add $ signs to your cell
reference so that your formula reads =B11*$B$5.
This instructs Excel to anchor the B5 cell reference
when the formula is copied to other cells, to not
change the column letter or row number. The cell
reference is absolute and the formula must always
use cell B5.
Cell Formula
C12 =B12*$B$5
C13 =B13*$B$5
In columns E to G in the worksheet, the volume discount that will be applied according
to the number of items purchased: 5% will be discounted if 1-5 items are purchased:
12% will be discounted if 6-9 items are purchased; and there is a discount of 15% for
buying more than 10..
The formula to calculate the final price will be: price including surcharge * volume
discount.
Let’s build that formula in cell E:
This is not correct. We actually needed to only fix the row number. This is called
a mixed reference.
Page | 15
University of Brighton Information Services
19. Use autofill to copy the new formula across columns F and G. Double click to
check the cell references in the formula of some of the newly populated cells.
22. Use autofill to copy the new formula across columns F and G. Double click to
check the cell references in the formula of
some of the newly populated cells.
This works!
Create an absolute reference by anchoring both column and row reference ($E$9)
Create a mixed reference to anchor just the row reference (e.g. E$9) or just the
column reference (e.g. $E9)
Leave a cell reference as relative so that both the column and row reference
update according to the formula’s position.
This spreadsheet shows the grade for each of our students. We are going to create a
rule that highlights in yellow where a student has attained grade A, B or C.
To do this, we will use the OR operator in our formula. This has the syntax:
=OR(first condition, second condition)
e.g. =OR(D2=”A”,D2=”B”,D2=”C”) will check if D2 contains A B or C.
Page | 17
University of Brighton Information Services
3. Click on the icon for our rule to change the range of cells to which we want to
apply this rule.
4. On the worksheet itself, use your mouse to select the cell range A2 to D10. Then
click to expand the Rules Manager again.
6. Open the rules manager and show the rules for the entire worksheet.
8. Add a $ sign before each column letter in your formula so that it reads
=OR($D2="A",$D2="B",$D2="C")
This will fix the column reference in the conditional formatting rule so that,
wherever you apply the rule, the rule will refer to that fixed column rather than
updating the rule.
In exercise 5 we used a similar spreadsheet to mark in red any months where the
target number of ghosts busted was not reached.
The rule applied to everyone in the sheet, which we feel is a little unfair as Junior
Ghostbusters are being compared directly against their more experienced Ghostbuster
colleagues.
To address this, we are going to create a rule that colours cells in red if the person has
the job title Ghostbuster and they have not reached the target number of ghosts
busted.
To do this, we will use the AND operator in our formula. This has the syntax:
=AND(first condition, second condition,…)
e.g. =AND(D2=D11,E2<E11) checks if D2 matches as D11 and that E2 is less than
E11).
2. Click in cell E2 and open up the Conditional Formatting Rules Manager and show
all rules for this worksheet.
3. Click on New Rule and click to choose Use a formula to determine which cells
to format
Page | 19
University of Brighton Information Services
4. When building the rule, we will build it for cell E2 as this is the first cell in the
range of cells to which we will apply our conditional formatting rule.
This formula will check whether the person has the job title Ghostbuster
(D2=D11) and the number of ghosts in cell E2 is less than the target specified in
call E11.
8. Click your mouse on the E11 cell reference in your formula and press the F4 key.
This will add dollar signs to make the cell reference absolute so that the formula
always checks against cell E11 when checking for the target number of ghosts
busted.
10. Click on the Format button, choose to fill the cells with red and click OK.
12. In the rules manager, click on the icon for our new rule to specify the range of
cells to which we want to apply this rule.
13. On the worksheet itself, use your mouse to select the cell range E2 to G7. Then
click to expand the Rules Manager again.
15. Create another rule to check whether the junior ghostbusters have met their
target in cell E12.
Page | 21
University of Brighton Information Services
Dates
Dates can be used in conditional formatting. For example, you can highlight where a
date has passed or when a deadline is near.
Click OK
Type =TODAY() in any empty cell on your sheet and press ENTER
This returns today’s date in the cell. Let’s see how we can use this in conditional
formatting.
This spreadsheet shows the due date and status for some projects running in our
department.
We are going to set conditional formatting to:
Mark the entire row in red for any projects where the due date has passed
Mark the entire row in yellow for any projects where the due date is in 2 weeks or
less
2. If you have downloaded the exercise file from our website, it will possibly be out
of date. So this exercise will work, change the dates in column C so that:
o C5 and C7 dates are in the past
o C4, C6, C8 and C9 are dates that are more than 2 weeks in the future
o C2, C3 and C10 are dates within the next 2 weeks.
For example, the dates shown at the top of the page would work for 9th March 2016.
3. Click in cell C2 and open up the Conditional Formatting Rules Manager and show
all rules for this worksheet.
4. Click on New Rule and click to choose Use a formula to determine which
cells to format
Page | 23
University of Brighton Information Services
5. When building the rule, we will build it for cell C2 as this is the first cell in the
range of cells to which we will apply our conditional formatting rule.
8. Click OK.
10. On the worksheet itself, use your mouse to select the cell range A2 to D10. Then
click to expand the Rules Manager again.
All of the rows with a date in the past are marked in red. Let’s mark the rows for any
projects nearing the deadline.
12. Click on cell C2 and open up the Conditional Formatting Rules Manager and
show all rules for this worksheet.
13. Click on New Rule and click to choose Use a formula to determine which cells
to format
14. When building the rule, we will again build it for cell C2 as this is the first cell in
the range of cells to which we will apply our conditional formatting rule.
19. On the worksheet itself, use your mouse to select the cell range A2 to D10. Then
click to expand the Rules Manager again.
For rows with a date in the past, both our rules are true. The date IS less than 2 weeks
from today AND is in the past.
Page | 25
University of Brighton Information Services
However, if two rules exist, only one can apply. The rule that is higher in the hierarchy
in the rules manager always takes precedence.
To control the order of rules in the hierarchy, use the buttons to move rules up
and down the list.
21. Move the yellow rule down so that it appears below the red row in the rules
hierarchy.
23. Add another rule to the top of the list to turn rows green if the status is
Completed in column D.
2. This workbook lists the number of hits each course we run received on our
website in 2012 and 2013.
Column C on the 2013 worksheet contains a VLOOKUP formula to check
whether the course existed in 2012.
Double click on cell C2 and then click on the icon on the formula bar to see how
VLOOKUP formulae are built. This formula checks:
Let’s try building a VLOOKUP into a conditional formatting rule. We’ll colour all cells in
column D on the 2013 sheet where value is larger than the number of hits for that
course in column C on the 2012 sheet.
3. Click in cell D2 and open up the Conditional Formatting Rules Manager and show
all rules for this worksheet.
Page | 27
University of Brighton Information Services
8. Click OK.
9. In the rules manager, click on the icon for our new rule to specify the range of
cells to which we want to apply this rule.
10. On the worksheet itself, use your mouse to select the cell range D2 to D28. Then
click to expand the Rules Manager again.
Exercise M. Filtering
2. Click in column D.
4. Click on Filter.
Page | 29