Contextures

Excel Conditional Formatting

Use Excel conditional formatting to highlight worksheet cells automatically, based on rules (conditions) that you set. Make cells a different colour, or change border, font style, or number format. Rules can be based on a selected cell's contents, or values in a different cell. See the simple examples below.

What is Excel Conditional Formatting?

With Excel conditional formatting, you can highlight one or cells, when specific conditions (rules) are met. :

For example, you can set a conditional formatting rules for a column where the cells contain a number:

  • turn the cell red if its value is below 50

That makes it easy to spot the months with low sales.

simple Conditional Formatting rule

How Does Conditional Formatting Work?

There are two steps for making conditional formatting work:

  1. Select the cells that you want to format automatically
  2. Set up the conditional formatting rule(s) for those cells

Usually, the rules are based on the contents of a cell -- the formatted cell, OR a different cell.

Here are examples of those 2 types of rules:

  1. Change a cell's colour to red, if its value is below 50
  2. Change all cells in a row blue, if the number in column B is below 30

What Cell Formatting Can You Change?

You can apply the following formats with your rules:

  • Number: apply different number formats
  • Font: show a different font style, or font colour, or add a strikethrough effect, or underline
    • You cannot change the font family, or font size
  • Fill: change the cell fill colour and fill pattern
  • Border: change the cell border colour and border style
    • You can't change the border thickness

What Cell Formatting Cannot Change?

In Conditional formatting, you cannot apply formatting options that would affect:

  • the row height, OR
  • the column width

For example, you cannot apply formatting to change any of the following:

  • font family
  • font size
  • superscript
  • subscript
  • border thickness

Border Options

On the Borders tab for normal cell formatting, there are 6 thin border options, and 7 thicker border options. Those options are shown at the left, in the image below.

On the Borders tab for Conditional Formatting, only the 6 thin border options are available. Those options are shown at the right in the image below.

list of months and units sold

Example 1: Cell Color Based on Amount

On this worksheet, there is a list of six months, and the units sold per month.

list of months and units sold

To quickly see the months with poor sales, we'll use conditional formatting to highlight numbers below 50, with light red cell fill colour.

simple Conditional Formatting rule

How to Highlight Low Numbers in List

To highlight the low numbers (below 50), follow these steps:

  • Select the number cells - B2:B7
  • On the Excel Ribbon, click the Home tab
  • In the Styles group, click the Conditional Formatting command

Conditional Formatting command in Styles group

  • Next, in the list of options, point to Highlight Cells Rules
  • In the next list that appears, click on Less Than

Highlight Cell Rules option and Less Than

The Less Than dialog box opens, with

  • a number automatically entered in the first box
  • cell formatting selected in the second box

On the worksheet, that formatting has been applied to some of the selected cells.

Less Than dialog box with default settings

Choose Settings for Less Than

Instead of leaving the default settings in the Less Than dialog box, make the following changes:

  • In the first box, type 50 -- we want to highlight numbers that are less than that number
  • In the second box, click the drop down arrow
  • Click on Light Red Fill
  • Click OK, to apply the Conditional Formatting to the selected cells

Less Than dialog box choose formatting

Conditional Formatting on Selected Cells

On the worksheet, the conditional formatting rule was applied to the selected cells

  • Cells with a number below 50 have light red fill color
  • Other cells have their original fill colour

Less Than dialog box choose formatting

Test the Conditional Formatting

To test the conditional formatting rule, make the following changes:

  • Change the January number to 33
    • Now it's below 50, and automatically gets light red fill colour
  • Change the May number to 52
    • Now it's NOT below 50, so the light red fill colour is automatically removed

worksheet numbers changed, fill colour updated

Less Than Dialog Default Settings

When the Less Than dialog box opens, there is a number in the first box.

To get that default number, here's what Excel does:

  • Find the highest number (Max) in the selected cells
  • Find the lowest number (Min) in the selected cells
  • Use the Average of those two numbers

Less Than dialog box default number calculation

For the default cell formatting, Excel shows the first item from the drop down list of options.

Less Than dialog box default number calculation

Example 2: Highlight With Top 10 Rule

A quick way to highlight cells is with the conditional formatting Top 10 rule. Despite its name of Top 10, you can adjust the rule to highlight any number of items

In this example, there are 6 months of sales amounts, for 4 different regions.

  • At the right, there is a total for each month
  • At the bottom, there is a total for each region
  • At the bottom right, there is a grand total

We'll highlight the top 5 sales amounts, using light green fill colour, without including any of the totals.

Here are the steps to highlight the top 5 amounts:

  • Select the number cells - B2:E7, where the region/month sales are entered
  • On the Excel Ribbon, click the Home tab
  • In the Styles group, click the Conditional Formatting command
  • Next, in the list of options, point to Top/Bottom Rules
  • In the next list that appears, click on Top 10 Items...

Top/Bottom Rules option and Top 10 items

The Top 10 Items dialog box opens, and

  • 10 is automatically entered in the first box
  • cell formatting is selected in the second box

On the worksheet, that formatting has been applied to the 10 highest amounts in the selected cells.

NOTE: If there are duplicate numbers, you might see more than 10 numbers highlighted

ten highest numbers highlighted

Set the Number

Instead of leaving the default settings in the Top 10 Items dialog box, make the following changes:

  • In the first box, type 5, or use the scroll buttons to change the number
  • In the second box, click the drop down arrow
  • Click on Custom Format
  • In the Format Cells dialog box, click on the Fill tab, then click on light green
  • Click OK to close the Format Cells dialog box
  • Click OK, to apply the Conditional Formatting to the selected cells

Top 10 Items and format cells

Conditional Formatting on Selected Cells

On the worksheet, the conditional formatting rule was applied to the selected cells

  • Cells with the top 5 amounts have light green fill
  • Other cells have their original fill colour

Top 10 Items highlighted with light green fill colour

Change Conditional Formatting Rule

After you create a conditional formatting rule, you might want to change it.

For example, in the previous example, a Top/Bottom rule was created, to highlight the top 5 amounts. Now, we'd like to change that Top/Bottom rule, and highlight only the top 3 amounts.

Existing Conditional Formatting Rule

If you want to change an existing Top/Bottom rule, or any other type of conditional formatting rule, do not choose the option again, from the list of Conditional Formatting options, in the drop down menu.

  • Choosing that option again will create a NEW rule, instead of changing the existing rule.
  • You'll end up with two conflicting rules, instead of one correct rule

To successfully change a conditional formatting rule, follow the steps below. Those steps show how to find the existing rule in the Conditional Formatting Rules Manager, and change it there.

Top/Bottom Rules option and Top 10 items

Correctly Change Existing Rule

In this example, a Top/Bottom rule was set up in cell B2:E7 (in the previous section)

To successfully change that existing conditional formatting rule, follow the steps below:

  • Select cells - B2:E7, where the original conditional formatting rule was applied
  • On the Excel Ribbon, click the Home tab
  • In the Styles group, click the Conditional Formatting command
  • Next, at the bottom of the list of options, click on Manage Rules

Top 10 Items highlighted with light green fill colour

Conditional Formatting Rules Manager

The Conditional Formatting Rules Manager opens, showing a list of rules for the selected cells.

  • Note: To see other rules, you can select from the "Show Formatting Rules For" drop down list, at the top of the Rules Manager dialog box.

Conditional Formatting Rules Manager list of rules

To change one of the conditional formatting rules:

  • Select a rule in the list, and click the Edit Rule button
  • In the Select a Rule Type section, the current rule type is highlighted
  • In the Edit the Rule Description section, the current settings are shown
    • In the screen shot below, the rule currently highlights the Top 5 values

Top 10 Items highlighted with light green fill colour

In the bottom section, Edit the Rule Description, you can make changes to the rule and its formatting

  • For this example, change the number of values to format, from 5 to 3
  • Click OK, to apply the rule change, and return to the worksheet
    • OR, click Cancel, and the rule will not be changed

Delete Conditional Formatting Rule

If you create a conditional formatting rule, you might want to delete that rule later. For example, you no longer want to highlight the top amounts.

To delete a rule, follow these steps:

  • Select cells - B2:E7, where the original conditional formatting rule was applied
  • On the Excel Ribbon, click the Home tab
  • In the Styles group, click the Conditional Formatting command
  • Next, at the bottom of the list of options, click on Manage Rules

Manage Rules command

Conditional Formatting Rules Manager

The Conditional Formatting Rules Manager dialog box opens, showing a list of rules for the selected cells.

NOTE: To see other rules, you can select from the drop down list at the top of the dialog box.

To delete one of the conditional formatting rules:

  • Select a rule in the list
  • At the top of the list, click the Delete Rule button
  • Click OK, to apply the rule change, and return to the worksheet
    • OR, click Cancel, and the rule will not be deleted

delete a rule

Video: Use 2 Rules to Format Cells

In this example, you'll set conditional formats that colour a cell, based on its own value. There will be 2 conditional formatting rules for the selected cells:

  • turn green if it contains a value higher than 75
  • turn red if it contains a value lower than 50.

This video shows the steps, and the written steps are below the video.

List on Worksheet

This example is shown in the video (above), and you can download the Excel file, to get the sample data.

Or, set up your own sample data, by following these steps.

  1. First, type the headings:
    • Cell D1: Month
    • Cell E1: Units
  2. Then, type a list of the month names in cells D2 to D13
  3. Next, type amounts in cells E2 to E13, using the sample data shown below as your guide

list with mopnths and amounts

Type Rule Amounts on Worksheet

When you're setting limits for your conditional formatting rules, those limits are easier to see and maintain, if you put them on a worksheet.

  • NOTE: In this example, the limits are entered on the same sheet as the formatted cells. However, you could put the limits on a different worksheet, so nobody accidentally changes them.

Follow these steps to set up the high and low amounts for the formatting rules:

  1. In cell I1, type the high value -- 75
  2. In cell I2, type the low value -- 50
  3. enter high low values

  4. Select the cells to be formatted. In this example, cells E2:E7 are selected.
  5. On the Ribbon's Home tab, click Conditional Formatting
  6. conditional formatting command

  7. To format the high values, click Highlight Cell Rules, then click Greater Than...
  8. enter high low values

  9. In the Greater Than window, delete the value that appears, and click on cell I1, where the High value is entered.
  10. enter cell reference

  11. Click the drop down list for formats, and click Custom Format.
  12. select custom format

  13. In the Format Cells window, click the Fill tab, and click on the green fill colour that you want.
  14. select custom format

  15. Click OK to close the Format Cells window, and click OK to close the Greater Than window.

The cells with values greater than 75 are now coloured green.

high values formatted

Apply 2nd Rule

To colour the low values in red fill, you can apply a second conditional formatting rule to the cells.

  1. Select the cells to be formatted. In this example, cells E2:E7 are selected.
  2. On the Ribbon's Home tab, click Conditional Formatting
  3. conditional formatting command

  4. To format the high values, click Highlight Cell Rules, then click Less Than...
  5. enter high low values

  6. In the Less Than window, delete the value that appears, and click on cell I2, where the Low value is entered.
  7. enter cell reference

  8. Click the drop down list for formats, and click Custom Format.
  9. select custom format

  10. In the Format Cells window, click the Fill tab, and click on the green fill colour that you want.
  11. select custom format

  12. Click OK to close the Format Cells window, and click OK to close the Less Than window.

The cells with values greater than 75 are now coloured green, and cells less than 50 are red.

high and low values formatted

Fix Conditional Formatting Extra Rules

After you set up conditional formatting rules, you might see a problem with new rules being created automatically -- you could end up with hundreds of extra rules!

This usually happens because a conditional formatting rule refers to a cell in a different row.

  • In the screen shot below, a new rule was added automatically when the entry in row 10 was deleted.
  • The rule refers to a cell in the current row (A3), and a cell in the row above (A2)
    • =$A2<>$A3

You can see how to clean up those extra rules, manually or with a macro, on the Fix Conditional Formatting Extra Rules page.

duplicate conditional formatting rules

Conditional Formatting Icons

In Excel 2007 and later versions, you can use built-in icon sets for conditional formatting. These icon set are a quick way to highlight the high, medium and low values in a list of numbers.

Many of the icon sets use shapes in the traditional colours of green, red and yellow. A few of the icon sets are in other colours, such as all grey, or black and white.

In this example, there is a list of month names, with quantities. We'll apply a conditional formatting icon set to highlight the high, medium and low quantities in that list.

list of months and units sold

To apply conditional formatting icons, follow these steps:

  • Select the number cells - B2:B7
  • On the Excel Ribbon, click the Home tab
  • In the Styles group, click the Conditional Formatting command
  • Next, in the list of options, point to Icon Sets
  • In the next list that appears, click on the first icon set in the Directional section.

conditional formatting icon sets

On the worksheet, that formatting has been applied to the selected cells.

  • High numbers have a green up arrow
  • Medium numbers have a yellow right arrow
  • Low numbers have a red down arrow

conditional formatting icon sets applied

Customize Your Own Icon Set

In Excel 2010 and later versions, you can customize the Conditional Formatting Icons, to some extent. Here’s how to do that, and build your own custom set of icons, by choosing from the individual built-in icons.

For this example, the list shows month names, and the number of errors recorded each month.

  • Currently, the icon set shows a green traffic light for high numbers and a red traffic light for low numbers.
  • We'd like the opposite colours applied, because a high number of errors is a bad thing, not a good thing!
  • None of the built-in icon sets have red, yellow, green in that order

conditional formatting icon sets traffic circles

Select Different Icons

Here's how to change the icons, to create a custom icon set for this data:

  • First, select the cells where the icon set was applied
  • On the Excel Ribbon, click the Home tab
  • In the Styles group, click the Conditional Formatting command
  • Next, at the bottom of the list of options, click on Manage Rules

The Conditional Formatting Rules Manager opens, showing a list of rules for the selected cells.

  • Select the icon set rule in the list, and click the Edit Rule button
  • In the Select a Rule Type section, the current rule type is highlighted
  • In the Edit the Rule Description section, the current Icon Style is shown
  • To change the first icon from green to red, click the down arrow, to see all the built-in icons
  • Click on the Red traffic circle icon
    • In the screen shot below, the 1st icon has been changed
  • Repeat that step, to change the 3rd icon from red to green
    • In the screen shot below, the 3rd icon is being changed

conditional formatting icon sets choosing icons

After you've selected your custom icons, complete these steps:

  • Click OK, to apply the rule change, and return to the worksheet
    • OR, click Cancel, and the icon set will not be changed

On the worksheet, the custom icon set has been applied to the selected cells.

  • High numbers have a red traffic circle - more errors in those months
  • Medium numbers have a yellow traffic circle
  • Low numbers have a green traffic circle -- fewer errors in those months

conditional formatting custom icons

Conditional Formatting Data Bars

If cells contain numbers, you can add conditional formatting data bars, to show the differences among the amounts.

Watch this short video to see how to set up data bars in a cell, and the written instructions are on the Conditional Formatting Data Bars page.

Pivot Table Conditional Formatting

To use conditional formatting in an Excel pivot table, you'll need to do a couple of extra steps. Otherwise, the conditional formatting will not adjust automatically, if you change the pivot table layout.

Watch this video to see the steps for applying conditional formatting to pivot tables cells.

Then the video shows how to adjust the rule, so new cells are correctly formatted if the pivot table layout changes. The written instructions are on the Pivot Table Conditional Formatting page.

Get the Sample File

Conditional Formatting Basics: Click here to get a zipped sample Conditional Formatting file with the examples from this tutorial. The zipped workbook is in xlsx format, and there are no macros in the file.

Pivot Table Conditional Formatting: To see the pivot tables example, download the Pivot Table Conditional Formatting workbook. The zipped Excel file is in xlsx file format, and does not contain any macros.

More Examples: For more Conditional Formatting rules and advanced examples, go to the Conditional Formatting Examples page.

Related Tutorials

Conditional Formatting - Based on another cell

Conditional Formatting - Examples

Fix Conditional Formatting Extra Rules

Conditional Formatting - Currency

Conditional Formatting - Documentation  

Conditional Formatting - Data Bars  

Last updated: December 28, 2021 12:08 PM