Excel format cells if value

Conditional formatting can help make patterns and trends in your data more apparent. To use it, you create rules that determine the format of cells based on their values, such as the following monthly temperature data with cell colors tied to cell values. 

Conditional formatting example

You can apply conditional formatting to a range of cells (either a selection or a named range), an Excel table, and in Excel for Windows, even a PivotTable report.

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

Conditional formatting typically works the same way in a range of cells, an Excel table, or a PivotTable report. However, conditional formatting in a PivotTable report has some extra considerations:

  • There are some conditional formats that don’t work with fields in the Values area of a PivotTable report. For example, you can’t format such fields based on whether they contain unique or duplicate values. These restrictions are mentioned in the remaining sections of this article, where applicable.

  • If you change the layout of the PivotTable report by filtering, hiding levels, collapsing and expanding levels, or moving a field, the conditional format is maintained as long as the fields in the underlying data are not removed.

  • The scope of the conditional format for fields in the Values area can be based on the data hierarchy and is determined by all the visible children (the next lower level in a hierarchy) of a parent (the next higher level in a hierarchy) on rows for one or more columns, or columns for one or more rows.

    Note: In the data hierarchy, children do not inherit conditional formatting from the parent, and the parent does not inherit conditional formatting from the children.

  • There are three methods for scoping the conditional format of fields in the Values area: by selection, by corresponding field, and by value field.

The default method of scoping fields in the Values area is by selection. You can change the scoping method to the corresponding field or value field by using the Apply formatting rule to option button, the New Formatting Rule dialog box, or the Edit Formatting Rule dialog box.

Method

Use this method if you want to select

Scoping by selection

  • A contiguous set of fields in the Values area, such as all of the product totals for one region.

  • A non-contiguous set of fields in the Values area, such as product totals for different regions across levels in the data hierarchy.

Scoping by value field

  • Avoid making many non-contiguous selections.

  • Conditionally format a set of fields in the Values area for all levels in the hierarchy of data.

  • Include subtotals and grand totals.

Scoping by corresponding field

  • Avoid making many non-contiguous selections.

  • Conditionally format a set of fields in the Values area for one level in the hierarchy of data.

  • Exclude subtotals.

When you conditionally format fields in the Values area for top, bottom, above average, or below average values, the rule is based on all visible values by default. However, when you scope by corresponding field, instead of using all visible values, you can apply the conditional format for each combination of:

  • A column and its parent row field.

  • A row and its parent column field.

Note: Quick Analysis is not available in Excel 2010 and previous versions.

Use the Quick Analysis button Quick Analysis button to apply selected conditional formatting to the selected data. The Quick Analysis button appears automatically when you select data.

  1. Select the data that you want to conditionally format. The Quick Analysis button appears on the lower-right corner of the selection.

    Selected data with the Quick Analysis button

  2. Click the Quick Analysis button Quick Analysis button, or press Ctrl+Q.

  3. In the pop-up that appears, on the Formatting tab, move your mouse over the different options to see a Live Preview on your data, and then click on the formatting option you want.

    Formatting tab in the Quick Analysis gallery

    Notes: 

    • The formatting options that appear in the Formatting tab depend on the data you have selected. If your selection contains only text, then the available options are Text, Duplicate, Unique, Equal To, and Clear. When the selection contains only numbers, or both text and numbers, then the options are Data Bars, Colors, Icon Sets, Greater, Top 10%, and Clear.

    • Live preview will only render for those formatting options that can be used on your data. For example, if your selected cells don’t contain matching data and you select Duplicate, the live preview will not work.

  4. If the Text that Contains dialog box appears, enter the formatting option you want to apply and click OK.

If you’d like to watch a video that shows how to use Quick Analysis to apply conditional formatting, see Video: Use conditional formatting.

You can download a sample workbook that contains different examples of applying conditional formatting, both with standard rules such as top and bottom, duplicates, Data Bars, Icon Sets and Color Scales, as well as manually creating rules of your own.

Download: Conditional formatting examples in Excel

Color scales are visual guides that help you understand data distribution and variation. A two-color scale helps you compare a range of cells by using a gradation of two colors. The shade of the color represents higher or lower values. For example, in a green and yellow color scale, as shown below, you can specify that higher value cells have a more green color and lower value cells have a more yellow color.

Tip: You can sort cells that have this format by their color — just use the context menu.

Formatting all cells with a two-color scale

Tip: If any cells in the selection contain a formula that returns an error, the conditional formatting is not applied to those cells. To ensure that the conditional formatting is applied to those cells, use an IS or IFERROR function to return a value other than an error value.

Quick formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Color Scales.

    Conditional Formatting

  3. Select a two-color scale.

    Hover over the color scale icons to see which icon is a two-color scale. The top color represents higher values, and the bottom color represents lower values.

You can change the method of scoping for fields in the Values area of a PivotTable report by using the Formatting Options button that appears next to a PivotTable field that has conditional formatting applied.

Advanced formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a completely new conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Apply Rule To, to optionally change the scope for fields in the Values area of a PivotTable report by:

    • Selection: Click Selected cells.

    • All cells for a Value label: Click All cells showing <Value label> values.

    • All cells for a Value label, excluding subtotals and the grand total: Click All cells showing <Value label> values for <Row Label>.

  5. Under Select a Rule Type, click Format all cells based on their values (default).

  6. Under Edit the Rule Description, in the Format Style list box, select 2-Color Scale.

  7. To select a type in the Type box for Minimum and Maximum, do one of the following:

    • Format lowest and highest values:    Select Lowest Value and Highest Value.

      In this case, you do not enter a Minimum and MaximumValue.

    • Format a number, date, or time value:    Select Number and then enter a Minimum and MaximumValue.

    • Format a percentage Percent:    Enter a Minimum and MaximumValue.

      Valid values are from 0 (zero) to 100. Don’t enter a percent sign.

      Use a percentage when you want to visualize all values proportionally because the distribution of values is proportional.

    • Format a percentile:    Select Percentile and then enter a Minimum and MaximumValue. Valid percentiles are from 0 (zero) to 100.

      Use a percentile when you want to visualize a group of high values (such as the top 20thpercentile) in one color grade proportion and low values (such as the bottom 20th percentile) in another color grade proportion, because they represent extreme values that might skew the visualization of your data.

    • Format a formula result:    Select Formula and then enter values for Minimum and Maximum.

      • The formula must return a number, date, or time value.

      • Start the formula with an equal sign (=).

      • Invalid formulas result in no formatting being applied.

      • It’s a good idea to test the formula to make sure that it doesn’t return an error value.

        Notes: 

        • Make sure that the Minimum value is less than the Maximum value.

        • You can choose a different type for the Minimum and Maximum. For example, you can choose a number for Minimum a percentage for Maximum.

  8. To choose a Minimum and Maximum color scale, click Color for each, and then select a color.

    If you want to choose additional colors or create a custom color, click More Colors. The color scale you select is shown in the Preview box.

Color scales are visual guides that help you understand data distribution and variation. A three-color scale helps you compare a range of cells by using a gradation of three colors. The shade of the color represents higher, middle, or lower values. For example, in a green, yellow, and red color scale, you can specify that higher value cells have a green color, middle value cells have a yellow color, and lower value cells have a red color.

Tip: You can sort cells that have this format by their color — just use the context menu.

Quick formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Color Scales.

    Conditional Formatting

  3. Select a three-color scale. The top color represents higher values, the center color represents middle values, and the bottom color represents lower values.

    Hover over the color scale icons to see which icon is a three-color scale.

You can change the method of scoping for fields in the Values area of a PivotTable report by using the Formatting Options button that appears next to a PivotTable field that has conditional formatting applied..

Advanced formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a new conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Apply Rule To, to optionally change the scope for fields in the Values area of a PivotTable report by:

    • Selection:    Click Just these cells.

    • Corresponding field:    Click All <value field> cells with the same fields.

    • Value field:    Click All <value field> cells.

  5. Under Select a Rule Type, click Format all cells based on their values.

  6. Under Edit the Rule Description, in the Format Style list box, select 3-Color Scale.

  7. Select a type for Minimum, Midpoint, and Maximum. Do one of the following:

    • Format lowest and highest values:    Select a Midpoint.

      In this case, you do not enter a Lowest and HighestValue.

    • Format a number, date, or time value:    Select Number and then enter a value for Minimum, Midpoint, and Maximum.

    • Format a percentage:    Select Percent and then enter a value for Minimum, Midpoint, and Maximum. Valid values are from 0 (zero) to 100. Do not enter a percent (%) sign.

      Use a percentage when you want to visualize all values proportionally, because using a percentage ensures that the distribution of values is proportional.

    • Format a percentile:    Select Percentile and then enter a value for Minimum, Midpoint, and Maximum.

      Valid percentiles are from 0 (zero) to 100.

      Use a percentile when you want to visualize a group of high values (such as the top 20th percentile) in one color grade proportion and low values (such as the bottom 20th percentile) in another color grade proportion, because they represent extreme values that might skew the visualization of your data.

    • Format a formula result:    Select Formula and then enter a value for Minimum, Midpoint, and Maximum.

      The formula must return a number, date, or time value. Start the formula with an equal sign (=). Invalid formulas result in no formatting being applied. It’s a good idea to test the formula to make sure that it doesn’t return an error value.

      Notes: 

      • You can set minimum, midpoint, and maximum values for the range of cells. Make sure that the value in Minimum is less than the value in Midpoint, which in turn is less than the value in Maximum.

      • You can choose a different type for Minimum, Midpoint, and Maximum. For example, you can choose a Minimum number, Midpoint percentile, and Maximum percent.

      • In many cases, the default Midpoint value of 50 percent works best, but you can adjust this to fit unique requirements.

  8. To choose a Minimum, Midpoint, and Maximum color scale, click Color for each, and then select a color.

    • To choose additional colors or create a custom color, click More Colors.

    • The color scale you select is shown in the Preview box.

A data bar helps you see the value of a cell relative to other cells. The length of the data bar represents the value in the cell. A longer bar represents a higher value, and a shorter bar represents a lower value. Data bars are useful in spotting higher and lower numbers, especially with large amounts of data, such as top selling and bottom selling toys in a holiday sales report.

The example shown here uses data bars to highlight dramatic positive and negative values. You can format data bars so that the data bar starts in the middle of the cell, and stretches to the left for negative values.

Data bars that highlight positive and negative values

Tip: If any cells in the range contain a formula that returns an error, the conditional formatting is not applied to those cells. To ensure that the conditional formatting is applied to those cells, use an IS or IFERROR function to return a value (such as 0 or «N/A») instead of an error value.

Quick formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Style group, click the arrow next to Conditional Formatting, click Data Bars, and then select a data bar icon.

    Conditional Formatting

You can change the method of scoping for fields in the Values area of a PivotTable report by using the Apply formatting rule to option button.

Advanced formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Apply Rule To, to optionally change the scope for fields in the Values area of a PivotTable report by:

    • Selection:    Click Just these cells.

    • Corresponding field:    Click All <value field> cells with the same fields.

    • Value field:    Click All <value field> cells.

  5. Under Select a Rule Type, click Format all cells based on their values.

  6. Under Edit the Rule Description, in the Format Style list box, select Data Bar.

  7. Select a Minimum and MaximumType. Do one of the following:

    • Format lowest and highest values:    Select Lowest Value and Highest Value.

      In this case, you do not enter a value for Minimum and Maximum.

    • Format a number, date, or time value:    Select Number and then enter a Minimum and MaximumValue.

    • Format a percentage:    Select Percent and then enter a value for Minimum and Maximum.

      Valid values are from 0 (zero) to 100. Do not enter a percent (%) sign.

      Use a percentage when you want to visualize all values proportionally, because using a percentage ensures that the distribution of values is proportional.

    • Format a percentile    Select Percentile and then enter a value for Minimum and Maximum.

      Valid percentiles are from 0 (zero) to 100.

      Use a percentile when you want to visualize a group of high values (such as the top 20th percentile) in one data bar proportion and low values (such as the bottom 20th percentile) in another data bar proportion, because they represent extreme values that might skew the visualization of your data.

    • Format a formula result     Select Formula, and then enter a value for Minimum and Maximum.

      • The formula has to return a number, date, or time value.

      • Start the formula with an equal sign (=).

      • Invalid formulas result in no formatting being applied.

      • It’s a good idea to test the formula to make sure that it doesn’t return an error value.

    Notes: 

    • Make sure that the Minimum value is less than the Maximum value.

    • You can choose a different type for Minimum and Maximum. For example, you can choose a Minimum number and a Maximum percent.

  8. To choose a Minimum and Maximum color scale, click Bar Color.

    If you want to choose additional colors or create a custom color, click More Colors. The bar color you select is shown in the Preview box.

  9. To show only the data bar and not the value in the cell, select Show Bar Only.

  10. To apply a solid border to data bars, select Solid Border in the Border list box and choose a color for the border.

  11. To choose between a solid bar and a gradiated bar, choose Solid Fill or Gradient Fill in the Fill list box.

  12. To format negative bars, click Negative Value and Axis and then, in the Negative Value and Axis Settings dialog box, choose options for the negative bar fill and border colors. You can choose position settings and a color for the axis. When you are finished selecting options, click OK.

  13. You can change the direction of bars by choosing a setting in the Bar Direction list box. This is set to Context by default, but you can choose between a left-to-right and a right-to-left direction, depending on how you want to present your data.

Use an icon set to annotate and classify data into three to five categories separated by a threshold value. Each icon represents a range of values. For example, in the 3 Arrows icon set, the green up arrow represents higher values, the yellow sideways arrow represents middle values, and the red down arrow represents lower values.

Tip: You can sort cells that have this format by their icon — just use the context menu.

The example shown here works with several examples of conditional formatting icon sets.

Different icon sets for the same data

You can choose to show icons only for cells that meet a condition; for example, displaying a warning icon for those cells that fall below a critical value and no icons for those that exceed it. To do this, you hide icons by selecting No Cell Icon from the icon drop-down list next to the icon when you are setting conditions. You can also create your own combination of icon sets; for example, a green «symbol» check mark, a yellow «traffic light», and a red «flag.»

Tip: If any cells in the selection contain a formula that returns an error, the conditional formatting is not applied to those cells. To ensure that the conditional formatting is applied to those cells, use an IS or IFERROR function to return a value (such as 0 or «N/A») instead of an error value.

Quick formatting

  1. Select the cells that you want to conditionally format.

  2. On the Home tab, in the Style group, click the arrow next to Conditional Formatting, click Icon Set, and then select an icon set.

    Conditional Formatting

You can change the method of scoping for fields in the Values area of a PivotTable report by using the Apply formatting rule to option button.

Advanced formatting

  1. Select the cells that you want to conditionally format.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Apply Rule To, to optionally change the scope for fields in the Values area of a PivotTable report by:

    • Selection:    Click Just these cells.

    • Corresponding field:    Click All <value field> cells with the same fields.

    • Value field:    Click All <value field> cells.

  5. Under Select a Rule Type, click Format all cells based on their values.

  6. Under Edit the Rule Description, in the Format Style list box, select Icon Set.

    1. Select an icon set. The default is 3 Traffic Lights (Unrimmed). The number of icons and the default comparison operators and threshold values for each icon can vary for each icon set.

    2. You can adjust the comparison operators and threshold values. The default range of values for each icon are equal in size, but you can adjust these to fit your unique requirements. Make sure that the thresholds are in a logical sequence of highest to lowest from top to bottom.

    3. Do one of the following:

      • Format a number, date, or time value:    Select Number.

      • Format a percentage:    Select Percent.

        Valid values are from 0 (zero) to 100. Do not enter a percent (%) sign.

        Use a percentage when you want to visualize all values proportionally, because using a percentage ensures that the distribution of values is proportional.

      • Format a percentile:    Select Percentile. Valid percentiles are from 0 (zero) to 100.

        Use a percentile when you want to visualize a group of high values (such as the top 20th percentile) using a particular icon and low values (such as the bottom 20th percentile) using another icon, because they represent extreme values that might skew the visualization of your data.

      • Format a formula result:    Select Formula, and then enter a formula in each Value box.

        • The formula must return a number, date, or time value.

        • Start the formula with an equal sign (=).

        • Invalid formulas result in no formatting being applied.

        • It’s a good idea to test the formula to make sure that it doesn’t return an error value.

    4. To make the first icon represent lower values and the last icon represent higher values, select Reverse Icon Order.

    5. To show only the icon and not the value in the cell, select Show Icon Only.

      Notes: 

      • You may need to adjust the column width to accommodate the icon.

      • The size of the icon shown depends on the font size that is used in that cell. As the size of the font is increased, the size of the icon increases proportionally.

To more easily find specific cells, you can format them by using a comparison operator. For example, in an inventory worksheet sorted by categories, you could highlight products with fewer than 10 items on hand in yellow. Or, in a retail store summary worksheet, you might identify all stores with profits greater than 10%, sales volumes less than $100,000, and region equal to «SouthEast.»

The examples shown here work with examples of built-in conditional formatting criteria, such as Greater Than, and Top %. This formats cities with a population greater than 2,000,000 with a green background and average high temperatures in the top 30% with orange.

Formatting shows cities with more than 2 million, and top 30% of high temperatures

Note: You cannot conditionally format fields in the Values area of a PivotTable report by text or by date, only by number.

Quick formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules.

    Conditional Formatting

  3. Select the command you want, such as Between, Equal To Text that Contains, or A Date Occurring.

  4. Enter the values you want to use, and then select a format.

You can change the method of scoping for fields in the Values area of a PivotTable report by using the Apply formatting rule to option button.

If you’d like to watch videos of these techniques, see Video: Conditionally format text and Video: Conditionally format dates.

Advanced formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet or on other worksheets, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Apply Rule To, to optionally change the scope for fields in the Values area of a PivotTable report by:

    • Selection:    Click Just these cells.

    • Corresponding field:    Click All <value field> cells with the same fields.

    • Value field:    Click All <value field> cells.

  5. Under Select a Rule Type, click Format only cells that contain.

  6. Under Edit the Rule Description, in the Format only cells with list box, do one of the following:

    • Format by number, date, or time:    Select Cell Value, select a comparison operator, and then enter a number, date, or time.

      For example, select Between and then enter 100 and 200, or select Equal to and then enter 1/1/2009.

      You can also enter a formula that returns a number, date, or time value.

      • If you enter a formula, start it with an equal sign (=).

      • Invalid formulas result in no formatting being applied.

      • It’s a good idea to test the formula to make sure that it doesn’t return an error value.

    • Format by text:    Select Specific Text, choosing a comparison operator, and then enter text.

      For example, select Contains and then enter Silver, or select Starting with and then enter Tri.

      Quotes are included in the search string, and you may use wildcard characters. The maximum length of a string is 255 characters.

      You can also enter a formula that returns text.

      • If you enter a formula, start it with an equal sign (=).

      • Invalid formulas result in no formatting being applied.

      • It’s a good idea to test the formula to make sure that it doesn’t return an error value.

      To see a video of this technique, see Video: Conditionally format text.

    • Format by date:    Select Dates Occurring and then select a date comparison.

      For example, select Yesterday or Next week.

      To see a video of this technique, see Video: Conditionally format dates.

    • Format cells with blanks or no blanks:    Select Blanks or No Blanks.

      A blank value is a cell that contains no data and is different from a cell that contains one or more spaces (spaces are considered as text).

    • Format cells with error or no error values:    Select Errors or No Errors.

      Error values include: #####, #VALUE!, #DIV/0!, #NAME?, #N/A, #REF!, #NUM!, and #NULL!.

  7. To specify a format, click Format. The Format Cells dialog box appears.

  8. Select the number, font, border, or fill format you want to apply when the cell value meets the condition, and then click OK.

    You can choose more than one format. The formats you select are shown in the Preview box.

You can find the highest and lowest values in a range of cells that are based on a cutoff value you specify. For example, you can find the top 5 selling products in a regional report, the bottom 15% products in a customer survey, or the top 25 salaries in a department .

Quick formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Top/Bottom Rules.

    Conditional Formatting

  3. Select the command you want, such as Top 10 items or Bottom 10 %.

  4. Enter the values you want to use, and then select a format.

You can change the method of scoping for fields in the Values area of a PivotTable report by using the Apply formatting rule to option button.

Advanced formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Apply Rule To, to optionally change the scope fields in the Values area of a PivotTable report by:

    • Selection:    Click Just these cells.

    • Corresponding field:    Click All <value field> cells with the same fields.

    • Value field:    Click All <value field> cells.

  5. Under Select a Rule Type, click Format only top or bottom ranked values.

  6. Under Edit the Rule Description, in the Format values that rank in the list box, select Top or Bottom.

  7. Do one of the following:

    • To specify a top or bottom number, enter a number and then clear the % of the selected range box. Valid values are 1 to 1000.

    • To specify a top or bottom percentage, enter a number and then select the % of the selected range box. Valid values are 1 to 100.

  8. Optionally, change how the format is applied for fields in the Values area of a PivotTable report that are scoped by corresponding field.

    By default, the conditional format is based on all visible values. However when you scope by corresponding field, instead of using all visible values, you can apply the conditional format for each combination of:

    • A column and its parent row field, by selecting each Column group.

    • A row and its parent column field, by selecting each Row group.

  9. To specify a format, click Format. The Format Cells dialog box appears.

  10. Select the number, font, border, or fill format you want to apply when the cell value meets the condition, and then click OK.

    You can choose more than one format. The formats you select are shown in the Preview box.

You can find values above or below an average or standard deviation in a range of cells. For example, you can find the above average performers in an annual performance review or you can locate manufactured materials that fall below two standard deviations in a quality rating.

Quick formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Top/Bottom Rules.

    Conditional Formatting

  3. Select the command you want, such as Above Average or Below Average.

  4. Enter the values you want to use, and then select a format.

You can change the method of scoping for fields in the Values area of a PivotTable report by using the Apply formatting rule to option button.

Advanced formatting

  1. Select one or more cells in a range, table, or PivotTable report.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Apply Rule To, to optionally change the scope for fields in the Values area of a PivotTable report by:

    • Selection:    Click Just these cells.

    • Corresponding field:    Click All <value field> cells with the same fields.

    • Value field:    Click All <value field> cells.

  5. Under Select a Rule Type, click Format only values that are above or below average.

  6. Under Edit the Rule Description, in the Format values that are list box, do one of the following:

    • To format cells that are above or below the average for all of the cells in the range, select Above or Below.

    • To format cells that are above or below one, two, or three standard deviations for all of the cells in the range, select a standard deviation.

  7. Optionally, change how the format is applied for fields in the Values area of a PivotTable report that are scoped by corresponding field.

    By default, the conditionally format is based on all visible values. However when you scope by corresponding field, instead of using all visible values, you can apply the conditional format for each combination of:

    • A column and its parent row field, by selecting each Column group.

    • A row and its parent column field, by selecting each Row group.

  8. Click Format to display the Format Cells dialog box.

  9. Select the number, font, border, or fill format you want to apply when the cell value meets the condition, and then click OK.

    You can choose more than one format. The formats you select are displayed in the Preview box.

Note: You can’t conditionally format fields in the Values area of a PivotTable report by unique or duplicate values.

In the example shown here, conditional formatting is used on the Instructor column to find instructors that are teaching more than one class (duplicate instructor names are highlighted in a pale red color). Grade values that are found just once in the Grade column (unique values) are highlighted in a green color.

Values in column C that aren't unique are colored rose, unique values in column D are green

Quick formatting

  1. Select the cells that you want to conditionally format.

  2. On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules.

    Conditional Formatting

  3. Select Duplicate Values.

  4. Enter the values you want to use, and then select a format.

Advanced formatting

  1. Select the cells that you want to conditionally format.

  2. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules. The Conditional Formatting Rules Manager dialog box appears.

  3. Do one of the following:

    • To add a conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet or table is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet, and then by selecting Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  4. Under Select a Rule Type, click Format only unique or duplicate values.

  5. Under Edit the Rule Description, in the Format all list box, select unique or duplicate.

  6. Click Format to display the Format Cells dialog box.

  7. Select the number, font, border, or fill format you want to apply when the cell value meets the condition, and then click OK.

    You can choose more than one format. The formats you select are shown in the Preview box.

If none of the above options is what you’re looking for, you can create your own conditional formatting rule in a few simple steps. 

Notes: If there’s already a rule defined that you just want to work a bit differently, duplicate the rule and edit it.

  1. Select Home > Conditional Formatting > Manage Rules, then in the Conditional Formatting Rule Manager dialog, select a listed rule and then select Duplicate Rule. The duplicate rule then appears in the list.

  2. Select the duplicate rule, then select Edit Rule.

  1. Select the cells that you want to format.

  2. On the Home tab, click Conditional Formatting > New Rule.

    New formatting rule

  3. Create your rule and specify its format options, then click OK.

    If you don’t see the options that you want, you can use a formula to determine which cells to format — see the next section for steps).

If you don’t see the exact options you need when you create your own conditional formatting rule, you can use a logical formula to specify the formatting criteria. For example, you may want to compare values in a selection to a result returned by a function or evaluate data in cells outside the selected range, which can be in another worksheet in the same workbook. Your formula must return True or False (1 or 0), but you can use conditional logic to string together a set of corresponding conditional formats, such as different colors for each of a small set of text values (for example, product category names).

Note: You can enter cell references in a formula by selecting cells directly on a worksheet or other worksheets. Selecting cells on the worksheet inserts absolute cell references. If you want Excel to adjust the references for each cell in the selected range, use relative cell references. For more information, see Create or change a cell reference and Switch between relative, absolute, and mixed references.

Tip: If any cells contain a formula that returns an error, conditional formatting is not applied to those cells. To address this, use IS functions or an IFERROR function in your formula to return a value that you specify (such as 0, or «N/A») instead of an error value.

  1. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules.

    Conditional Formatting

    The Conditional Formatting Rules Manager dialog box appears.

  2. Do one of the following:

    • To add a conditional format, click New Rule. The New Formatting Rule dialog box appears.

    • To add a new conditional format based on one that is already listed, select the rule, then click Duplicate Rule. The duplicate rule is copied and appears in the dialog box. Select the duplicate, then select Edit Rule. The Edit Formatting Rule dialog box appears. 

    • To change a conditional format, do the following:

      1. Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.

      2. Optionally, change the range of cells by clicking Collapse Dialog in the Applies to box to temporarily hide the dialog box, by selecting the new range of cells on the worksheet or other worksheets, and then by clicking Expand Dialog.

      3. Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.

  3. Under Apply Rule To, to optionally change the scope for fields in the Values area of a PivotTable report, do the following:

    • To scope by selection:    Click Selected cells.

    • To scope by corresponding field:    Click All cells showing <Values field> values.

    • To scope by Value field:    Click All cells showing <Values field> for <Row>.

  4. Under Select a Rule Type, click Use a formula to determine which cells to format.

    1. Under Edit the Rule Description, in the Format values where this formula is true list box, enter a formula.

      You have to start the formula with an equal sign (=), and the formula must return a logical value of TRUE (1) or FALSE (0).

    2. Click Format to display the Format Cells dialog box.

    3. Select the number, font, border, or fill format you want to apply when the cell value meets the condition, and then click OK.

      You can choose more than one format. The formats you select are shown in the Preview box.

      Example 1: Use two conditional formats with criteria that uses AND and OR tests    

      The following example shows the use of two conditional formatting rules. If the first rule doesn’t apply, the second rule applies.

      First rule: a home buyer has budgeted up to $75,000 as a down payment and $1,500 per month as a mortgage payment. If both the down payment and the monthly payments fit these requirements, cells B4 and B5 are formatted green.

      Second rule: if either the down payment or the monthly payment doesn’t meet the buyer’s budget, B4 and B5 are formatted red. Change some values, such as the APR, the loan term, the down payment, and the purchase amount to see what happens with the conditionally formatted cells.

      Formula for first rule (applies green color)

      =AND(IF($B$4<=75000,1),IF(ABS($B$5)<=1500,1))

      Formula for second rule (applies red color)

      =OR(IF($B$4>=75000,1),IF(ABS($B$5)>=1500,1))

      Cells B4 and B5 meet their conditions, so they're formatted green

      Example 2: Shade every other row by using the MOD and ROW functions    

      A conditional format applied to every cell in this worksheet shades every other row in the range of cells with a blue cell color. You can select all cells in a worksheet by clicking the square above row 1 and to the left of column A. The MOD function returns a remainder after a number (the first argument) is divided by divisor (the second argument). The ROW function returns the current row number. When you divide the current row number by 2, you always get either a 0 remainder for an even number or a 1 remainder for an odd number. Because 0 is FALSE and 1 is TRUE, every odd numbered row is formatted. The rule uses this formula: =MOD(ROW(),2)=1.

      Every other row is shaded blue

      Note: You can enter cell references in a formula by selecting cells directly on a worksheet or other worksheets. Selecting cells on the worksheet inserts absolute cell references. If you want Excel to adjust the references for each cell in the selected range, use relative cell references. For more information, see Create or change a cell reference and Switch between relative, absolute, and mixed references.

The following video shows you the basics of using formulas with conditional formatting.

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

If you want to apply an existing formatting style to new or other data on your worksheet, you can use Format Painter to copy the conditional formatting to that data.

  1. Click the cell that has the conditional formatting that you want to copy.

  2. Click Home > Format Painter.

    Copy and Paste buttons on the Home tab

    The pointer changes to a paintbrush.

    Tip: You can double-click Format Painter if you want to keep using the paintbrush to paste the conditional formatting in other cells.

  3. To paste the conditional formatting, drag the paintbrush across the cells or ranges of cells you want to format.

  4. To stop using the paintbrush, press Esc.

Note: If you’ve used a formula in the rule that applies the conditional formatting, you might have to adjust any cell references in the formula after pasting the conditional format. For more information, see Switch between relative, absolute, and mixed references.

If your worksheet contains conditional formatting, you can quickly locate the cells so that you can copy, change, or delete the conditional formats. Use the Go To Special command to find only cells with a specific conditional format, or to find all cells that have conditional formats.

Find all cells that have a conditional format

  1. Click any cell that does not have a conditional format.

  2. On the Home tab, in the Editing group, click the arrow next to Find & Select, and then click Conditional Formatting.

    Editing group on the Home tab

Find only cells that have the same conditional format

  1. Click any cell that has the conditional format that you want to find.

  2. On the Home tab, in the Editing group, click the arrow next to Find & Select, and then click Go To Special.

  3. Click Conditional formats.

  4. Click Same under Data validation.

    Editing group on the Home tab

When you use conditional formatting, you set up rules that Excel uses to determine when to apply the conditional formatting. To manage these rules, you should understand the order in which these rules are evaluated, what happens when two or more rules conflict, how copying and pasting can affect rule evaluation, how to change the order in which rules are evaluated, and when to stop rule evaluation.

  • Learn about conditional formatting rule precedence

    You create, edit, delete, and view all conditional formatting rules in the workbook by using the Conditional Formatting Rules Manager dialog box. (On the Home tab, click Conditional Formatting, and then click Manage Rules.)

    Conditional Formatting menu with Manage Rules highlighted

    The Conditional Formatting Rules Manager dialog box appears.

    When two or more conditional formatting rules apply, these rules are evaluated in order of precedence (top to bottom) by how they are listed in this dialog box.

    Here’s an example that has expiration dates for ID badges. We want to mark badges that expire within 60 days but are not yet expired with a yellow background color, and expired badges with a red background color.

    Conditionally formatted data

    In this example, cells with employee ID numbers who have certification dates due to expire within 60 days are formatted in yellow, and ID numbers of employees with an expired certification are formatted in red. The rules are shown in the following image.

    Conditional formatting rules

    The first rule (which, if True, sets cell background color to red) tests a date value in column B against the current date (obtained by using the TODAY function in a formula). Assign the formula to the first data value in column B, which is B2. The formula for this rule is =B2<TODAY(). This formula tests the cells in column B (cells B2:B15). If the formula for any cell in column B evaluates to True, its corresponding cell in column A (for example, A5 corresponds to B5, A11 corresponds to B11), is then formatted with a red background color. After all the cells specified under Applies to are evaluated with this first rule, the second rule is tested. This formula checks if values in the B column are less than 60 days from the current date (for example, suppose today’s date is 8/11/2010). The cell in B4, 10/4/2010, is less than 60 days from today, so it evaluates as True, and is formatted with a yellow background color. The formula for this rule is =B2<TODAY()+60. Any cell that was first formatted red by the highest rule in the list is left alone.

    A rule higher in the list has greater precedence than a rule lower in the list. By default, new rules are always added to the top of the list and therefore have a higher precedence, so you’ll want to keep an eye on their order. You can change the order of precedence by using the Move Up and Move Down arrows in the dialog box.

    Move Up and Move Down arrows

  • What happens when more than one conditional formatting rule evaluates to True

    Sometimes you have more than one conditional formatting rule that evaluates to True. Here’s how rules are applied, first when rules don’t conflict, and then when they do conflict:

    When rules don’t conflict     For example, if one rule formats a cell with a bold font and another rule formats the same cell with a red color, the cell is formatted with both a bold font and a red color. Because there is no conflict between the two formats, both rules are applied.

    When rules conflict     For example, one rule sets a cell font color to red and another rule sets a cell font color to green. Because the two rules are in conflict, only one can apply. The rule that is applied is the one that is higher in precedence (higher in the list in the dialog box).

  • How pasting, filling, and the Format Painter affect conditional formatting rules

    While editing your worksheet, you may copy and paste cell values that have conditional formats, fill a range of cells with conditional formats, or use the Format Painter. These operations can affect conditional formatting rule precedence in the following way: a new conditional formatting rule based on the source cells is created for the destination cells.

    If you copy and paste cell values that have conditional formats to a worksheet opened in another instance of Excel (another Excel.exe process running at the same time on the computer), no conditional formatting rule is created in the other instance and the format is not copied to that instance.

  • What happens when a conditional format and a manual format conflict

    If a conditional formatting rule evaluates as True, it takes precedence over any existing manual format for the same selection. This means that if they conflict, the conditional formatting applies and the manual format does not. If you delete the conditional formatting rule, the manual formatting for the range of cells remains.

    Manual formatting is not listed in the Conditional Formatting Rules Manager dialog box nor is it used to determine precedence.

  • Controlling when rule evaluation stops by using the Stop If True check box

    For backwards compatibility with versions of Excel earlier than Excel 2007, you can select the Stop If True check box in the Manage Rules dialog box to simulate how conditional formatting might appear in those earlier versions of Excel that do not support more than three conditional formatting rules or multiple rules applied to the same range.

    For example, if you have more than three conditional formatting rules for a range of cells, and are working with a version of Excel earlier than Excel 2007, that version of Excel:

    • Evaluates only the first three rules.

    • Applies the first rule in precedence that is True.

    • Ignores rules lower in precedence if they are True.

    The following table summarizes each possible condition for the first three rules:

    If rule

    Is

    And if rule

    Is

    And if rule

    Is

    Then

    One

    True

    Two

    True or False

    Three

    True or False

    Rule one is applied and rules two and three are ignored.

    One

    False

    Two

    True

    Three

    True or False

    Rule two is applied and rule three is ignored.

    One

    False

    Two

    False

    Three

    True

    Rule three is applied.

    One

    False

    Two

    False

    Three

    False

    No rules are applied.

    You can select or clear the Stop If True check box to change the default behavior:

    • To evaluate only the first rule, select the Stop If True check box for the first rule.

    • To evaluate only the first and second rules, select the Stop If True check box for the second rule.

    You can’t select or clear the Stop If True check box if the rule formats by using a data bar, color scale, or icon set.

If you’d like to watch a video showing how to manage conditional formatting rules, see Video: Manage conditional formatting.

The order in which conditional formatting rules are evaluated — their precedence — also reflects their relative importance: the higher a rule is on the list of conditional formatting rules, the more important it is. This means that in cases where two conditional formatting rules conflict with each other, the rule that is higher on the list is applied and the rule that is lower on the list is not applied.

  1. On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Manage Rules.

    Conditional Formatting menu with Manage Rules highlighted

    The Conditional Formatting Rules Manager dialog box appears.

    The conditional formatting rules for the current selection are displayed, including the rule type, the format, the range of cells the rule applies to, and the Stop If True setting.

    If you don’t see the rule that you want, in the Show formatting rules for list box, make sure that the right range of cells, worksheet, table, or PivotTable report is selected.

  2. Select a rule. Only one rule can be selected at a time.

  3. To move the selected rule up in precedence, click Move Up. To move the selected rule down in precedence, click Move Down.

    Move Up and Move Down arrows

  4. Optionally, to stop rule evaluation at a specific rule, select the Stop If True check box.

Clear conditional formatting on a worksheet    

  • On the Home tab, click Conditional Formatting > Clear Rules > Clear Rules from Entire Sheet.

Follow these steps if you have conditional formatting in a worksheet, and you need to remove it.

For an entire
worksheet

  • On the Home tab, click Conditional Formatting > Clear Rules > Clear Rules from Entire Sheet.

In a range of cells

  1. Select the cells that contain the conditional formatting.

  2. Click the Quick Analysis Lens button image button that appears to the bottom right of the selected data.

    Notes: 
    Quick Analysis Lens will not be visible if:

    • All of the cells in the selected range are empty, or

    • There is an entry only in the upper-left cell of the selected range, with all of the other cells in the range being empty.

  3. Click Clear Format.

    Clear option

Find and remove the same conditional formats throughout a worksheet

  1. Click on a cell that has the conditional format that you want to remove throughout the worksheet.

  2. On the Home tab, click the arrow next to Find & Select, and then click Go To Special.

  3. Click Conditional formats.

  4. Click Same under Data validation. to select all of the cells that contain the same conditional formatting rules.

  5. On the Home tab, click Conditional Formatting > Clear Rules > Clear Rules from Selected Cells.

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

Tip: The following sections use examples so you can follow along in Excel for the web. To start, download the Conditional Formatting Examples workbook and save it to OneDrive. Then, open OneDrive in a web browser and select the downloaded file.

  1. Select the cells you want to format, then select Home > Styles > Conditional Formatting > New Rule. You can also open the Conditional Formatting pane and create a new rule without first selecting a range of cells.

    New Rule step 1

  2. Verify or adjust the cells in Apply to range.

  3. Choose a Rule Type and adjust the options to meet your needs. 

  4. When finished, select Done and the rule will be applied to your range.

  1. Select a cell which has a conditional format you want to change. Or you can select Home > Styles > Conditional Formatting > Manage Rules to open the Conditional Formatting task pane and select an existing rule.

  2. The Conditional Formatting task pane displays any rules which apply to specific cells or ranges of cells.

    Image showing step 2 of editing a Conditional Formatting rule

  3. Hover over the rule and select Edit by clicking the pencil icon. This opens the task pane for rule editing. 

  4. Modify the rule settings and click Done to apply the changes.

The Conditional Formatting task pane provides everything you need for creating, editing, and deleting rules. Use Manage Rules to open the task pane and work with all the Conditional Formatting rules in a selection or a sheet.

  1. In an open workbook, select Home > Styles > Conditional Formatting > Manage Rules.

  2. The Conditional Formatting task pane opens and displays the rules, scoped to your current selection. 

Manage Rules in the task pane

From here, you can: 

  • Choose a different scope on the Manage Rules in menu — for example, choosing this sheet tells Excel to look for all rules on the current sheet.

  • Add a rule by selecting New Rule (the plus sign).

  • Delete all rules in scope by selecting Delete All Rules (the garbage can).

You can use a formula to determine how Excel evaluates and formats a cell.  Open the Conditional Formatting pane and select an existing rule or create a new rule.

In the Rule Type dropdown, select Formula.

Select Formula Rule

Enter the formula in the box. You can use any formula that returns a logical value of TRUE (1) or FALSE (0), but you can use AND and OR to combine a set of logical checks.

For example, =AND(B3=»Grain»,D3<500) is true for a cell in row 3 if both B3=»Grain» and D3<500 are true.

Formula rule type

You can clear conditional formatting in selected cells or the entire worksheet.

  • To clear conditional formatting in selected cells, select the cells in the worksheet. Then Select Home > Styles > Conditional Formatting > Clear Rules > Clear Rules from Selected Cells.

  • To clear conditional formatting in the entire worksheet, select Home > Styles > Conditional Formatting > Clear Rules > Clear Rules from Entire Sheet.

  • To delete conditional formatting rules, select Home > Styles > Conditional Formatting >Manage Rules and use the delete (garbage can) on a specific rule or the Delete all rules button.

Color scales are visual guides which help you understand data distribution and variation. Excel offers both two-color scales and three-color scales. 

A two-color scale helps you compare a range of cells by using a gradation of two colors. The shade of the color represents higher or lower values. For example, in a green and yellow color scale, you can specify that higher value cells be more green and lower value cells have a more yellow.

Two color scale formatting

A three-color scale helps you compare a range of cells by using a gradation of three colors. The shade of the color represents higher, middle, or lower values. For example, in a green, yellow, and red color scale, you can specify that higher value cells have a green color, middle value cells have a yellow color, and lower value cells have a red color.

Three color scale formatting

Tip: You can sort cells that have one of these formats by their color — just use the context menu.

  1. Select the cells that you want to conditionally format using color scales.

  2. Click Home > Styles > Conditional Formatting > Color Scales and select a color scale.

A data bar helps you see the value of a cell relative to other cells. The length of the data bar represents the value in the cell. A longer bar represents a higher value, and a shorter bar represents a lower value. Data bars are useful in spotting higher and lower numbers, especially with large amounts of data, such as top selling and bottom selling toys in a holiday sales report.

Data bars

  1. Select the cells that you want to conditionally format.

  2. Select Home > Styles > Conditional Formatting > Data Bars and select a style. 

Use an icon set to annotate and classify data into three to five categories separated by a threshold value. Each icon represents a range of values. For example, in the 3 Arrows icon set, the green up arrow represents higher values, the yellow sideways arrow represents middle values, and the red down arrow represents lower values.

Icon set

  1. Select the cells that you want to conditionally format.

  2. Select Home > Styles > Conditional Formatting > Icon Sets and choose an icon set.

This option lets you highlight specific cell values within a range of cells based on their specific contents. This can be especially useful when working with data sorted using a different range.

For example, in an inventory worksheet sorted by categories, you could highlight the names of products where you have fewer than 10 items in stock so it’s easy to see which products need restocking without resorting the data. 

  1. Select the cells that you want to conditionally format.

  2. Select Home > Styles > Conditional Formatting > Highlight Cell Rules.

  3. Select the comparison, such as Between, Equal To, Text That Contains, or A Date Occurring.

You can highlight the highest and lowest values in a range of cells which are based on a specified cutoff value.

Some examples of this would include highlighting the top five selling products in a regional report, the bottom 15% products in a customer survey, or the top 25 salaries in a department.

  1. Select the cells that you want to conditionally format.

  2. Select Home > Styles > Conditional Formatting > Top/Bottom Rules.

  3. Select the command you want, such as Top 10 items or Bottom 10 %.

  4. Enter the values you want to use, and select a format (fill, text, or border color).

You can highlight values above or below an average or standard deviation in a range of cells.

For example, you can find the above-average performers in an annual performance review, or locate manufactured materials that fall below two standard deviations in a quality rating.

  1. Select the cells that you want to conditionally format.

  2. Select Home> Styles > Conditional Formatting > Top/Bottom Rules.

  3. Select the option you want, such as Above Average or Below Average.

  4. Enter the values you want to use, and select a format (fill, text, or border color).

  1. Select the cells that you want to conditionally format.

  2. Select Home > Styles > Conditional Formatting > Highlight Cell Rules > Duplicate Values.

  3. Enter the values you want to use, and select a format (fill, text, or border color).

If you want to apply an existing formatting style to other cells on your worksheet, use Format Painter to copy the conditional formatting to that data.

  1. Click the cell that has the conditional formatting you want to copy.

  2. Click Home > Format Painter.

    Copy and Paste buttons on the Home tab

    The pointer will change to a paintbrush.

    Tip: You can double-click Format Painter if you want to keep using the paintbrush to paste the conditional formatting in other cells.

  3. Drag the paintbrush across the cells or range of cells you want formatted.

  4. To stop using the paintbrush, press Esc.

Note: If you’ve used a formula in the rule that applies the conditional formatting, you might have to adjust relative and absolute references in the formula after pasting the conditional format. For more information, see Switch between relative, absolute, and mixed references.

Note: You can’t use conditional formatting on external references to another workbook.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

See Also

Conditional formatting compatibility issues

Содержание

  1. Conditional Formatting If Between Two Numbers – Excel & Google Sheets
  2. Conditional Formatting if Between Two Numbers
  3. Alternate Method – Custom Formula
  4. Highlight Cells Between Two Numbers in Google Sheets
  5. Custom Formula in Google Sheets
  6. IF function
  7. Simple IF examples
  8. Common problems
  9. Need more help?
  10. Conditional formatting with formulas
  11. Summary
  12. Quick Links
  13. Quick start
  14. Formula logic
  15. Formula Examples
  16. Highlight orders from Texas
  17. Highlight dates in the next 30 days
  18. Highlight column differences
  19. Highlight missing values
  20. Highlight properties with 3+ bedrooms under $350k
  21. Highlight top values (dynamic example)
  22. Gantt charts
  23. Simple search box
  24. Troubleshooting
  25. Dummy Formulas
  26. Limitations

Conditional Formatting If Between Two Numbers – Excel & Google Sheets

This tutorial will demonstrate how to highlight cells that contain a value between two other specified values in Excel and Google Sheets.

Conditional Formatting if Between Two Numbers

To highlight cells where the value is between a set minimum and maximum (inclusive), you can use one of the built-in Highlight Cell Rules within the Conditional Formatting menu.

  1. Select the range you want to apply formatting to.
  2. In the Ribbon, select Home > Conditional Formatting > Highlight Cells Rules > Between…

  1. You can either type in the bottom and top values, or to make the formatting dynamic (i.e., the result will change if you change the cells), click on the cells that contain the bottom and top values. Click OK.

Values between 20 and 70 (inclusive) are highlighted.

  1. When you change the two values in Cells H4 and H5, you obtain a different result.

Alternate Method – Custom Formula

You can also highlight cells between two specified numbers by creating a New Rule and selecting Use a formula to determine which cells to format.

  1. Select New Rule from the Conditional Formatting menu.

  1. Select Use a formula to determine which cells to format, and enter the formula (using the AND Function):
  1. The reference to cells H3 and H5 need to be locked by making them absolute. You can do this by using the $ sign around the row and column indicators, or by pressing F4 on the keyboard.
    To learn more about how symbols are used in Excel, see How to Insert Signs and Symbols.
  2. Click on the Format button.

  1. Choose a fill color for the highlighted cells.

  1. Click OK, then OK again to return to the Conditional Formatting Rules Manager.

  1. Click Apply to apply the format to your worksheet.

Highlight Cells Between Two Numbers in Google Sheets

Highlighting cells between two numbers in Google Sheets is similar.

  1. Highlight the cells you wish to format, and then click on Format > Conditional Formatting.

  1. The Apply to Range section will already be filled in.

  1. From the Format Rules section, select Is Between from the drop-down list and set the minimum and maximum values.

  1. Once again, you need to use the absolute signs (dollar signs) to lock in the values in Cells H4 and H5.
  2. Select the fill style for the cells that meet the criteria.

  1. Click Done to apply the rule.

Custom Formula in Google Sheets

  1. To use a custom formula rather than a built-in rule, select Custom formula is under Format Rules, and type the formula.

Remember to use $s or the F4 key to make Cells H4 and H5 absolute.

  1. Select your formatting and click Done.

Источник

IF function

The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.

So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.

For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.

IF(logical_test, value_if_true, [value_if_false])

The condition you want to test.

The value that you want returned if the result of logical_test is TRUE.

The value that you want returned if the result of logical_test is FALSE.

Simple IF examples

In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)

In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.

B2,”Over Budget”,”Within Budget”)» loading=»lazy»>

=IF(C2>B2,”Over Budget”,”Within Budget”)

In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)

B2,C2-B2,»»)» loading=»lazy»>

In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).

In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)

Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.

Common problems

What went wrong

There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument.

This usually means that the formula is misspelled.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

Источник

Conditional formatting with formulas

Summary

Although Excel ships with many conditional formatting «presets», these are limited. A more powerful way to apply conditional formatting is with formulas, because formulas allow you to apply rules that use more sophisticated logic. This article shows 10 examples, including how to highlight rows, column differences, missing values, and how to build Gantt charts and search boxes with conditional formatting.

Quick Links

Conditional formatting is a fantastic way to quickly visualize data in a spreadsheet. With conditional formatting, you can do things like highlight dates in the next 30 days, flag data entry problems, highlight rows that contain top customers, show duplicates, and more.

Excel ships with a large number of «presets» that make it easy to create new rules without formulas. However, you can also create rules with your own custom formulas. By using your own formula, you take over the condition that triggers a rule and can apply exactly the logic you need. Formulas give you maximum power and flexibility.

For example, using the «Equal to» preset, it’s easy to highlight cells equal to «apple».

But what if you want to highlight cells equal to «apple» or «kiwi» or «lime»? Sure, you can create a rule for each value, but that’s a lot of trouble. Instead, you can simply use one rule based on a formula with the OR function:

Here’s the result of the rule applied to the range B4:F8 in this spreadsheet:

Here’s the exact formula used:

Quick start

You can create a formula-based conditional formatting rule in four easy steps:

1. Select the cells you want to format.

2. Create a conditional formatting rule, and select the Formula option

3. Enter a formula that returns TRUE or FALSE.

4. Set formatting options and save the rule.

The ISODD function only returns TRUE for odd numbers, triggering the rule:

Formula logic

Formulas that apply conditional formatting must return TRUE or FALSE, or numeric equivalents. Here are some examples:

The above formulas all return TRUE or FALSE, so they work perfectly as a trigger for conditional formatting.

When conditional formatting is applied to a range of cells, enter cell references with respect to the first row and column in the selection (i.e. the upper-left cell). The trick to understanding how conditional formatting formulas work is to visualize the same formula being applied to each cell in the selection, with cell references updated as usual. Imagine that you entered the formula in the upper-left cell of the selection, and then copied the formula across the entire selection. If you struggle with this, see the section on Dummy Formulas below.

Formula Examples

Below are examples of custom formulas you can use to apply conditional formatting. Some of these examples can be created using Excel’s built-in presets for highlighting cells, but custom formulas can go far beyond presets, as you can see below.

Highlight orders from Texas

To highlight rows that represent orders from Texas (abbreviated TX), use a formula that locks the reference to column F:

Highlight dates in the next 30 days

To highlight dates occurring in the next 30 days, we need a formula that (1) makes sure dates are in the future and (2) makes sure dates are 30 days or less from today. One way to do this is to use the AND function together with the NOW function like this:

With a current date of August 18, 2016, the conditional formatting highlights dates as follows:

The NOW function returns the current date and time. For details about how this formula, works, see this article: Highlight dates in the next N days.

Highlight column differences

Given two columns that contain similar information, you can use conditional formatting to spot subtle differences. The formula used to trigger the formatting below is:

Highlight missing values

To highlight values in one list that are missing from another, you can use a formula based on the COUNTIF function:

This formula simply checks each value in List A against values in the named range «list» (D5:D10). When the count is zero, the formula returns TRUE and triggers the rule, which highlights values in List A that are missing from List B.

Highlight properties with 3+ bedrooms under $350k

To find properties in this list that have at least 3 bedrooms but are less than $300,000, you can use a formula based on the AND function:

The dollar signs ($) lock the reference to columns C and D, and the AND function is used to make sure both conditions are TRUE. In rows where the AND function returns TRUE, the conditional formatting is applied:

Highlight top values (dynamic example)

Although Excel has presets for «top values», this example shows how to do the same thing with a formula, and how formulas can be more flexible. By using a formula, we can make the worksheet interactive — when the value in F2 is updated, the rule instantly responds and highlights new values.

The formula used for this rule is:

Where «data» is the named range B4:G11, and «input» is the named range F2. This page has details and a full explanation.

Gantt charts

Believe it or not, you can even use formulas to create simple Gantt charts with conditional formatting like this:

This worksheet uses two rules, one for the bars, and one for the weekend shading:

Simple search box

One cool trick you can do with conditional formatting is to build a simple search box. In this example, a rule highlights cells in column B that contain text typed in cell F2:

The formula used is:

For more details and a full explanation, see:

Troubleshooting

If you can’t get your conditional formatting rules to fire correctly, there’s most likely a problem with your formula. First, make sure you started the formula with an equals sign (=). If you forget this step, Excel will silently convert your entire formula to text, rendering it useless. To fix, just remove the double quotes Excel added at either side and make sure the formula begins with equals (=).

If your formula is entered correctly but is not triggering the rule, you may have to dig a little deeper. Normally, you can use the F9 key to check results in a formula or use the Evaluate feature to step through a formula. Unfortunately, you can’t use these tools with conditional formatting formulas, but you can use a technique called «dummy formulas».

Dummy Formulas

Dummy formulas are a way to test your conditional formatting formulas directly on the worksheet, so you can see what they’re actually doing. This can be a big time-saver when you’re struggling to get cell references working correctly.

In a nutshell, you enter the same formula across a range of cells that matches the shape of your data. This lets you see the values returned by each formula, and it’s a great way to visualize and understand how formula-based conditional formatting works. For a detailed explanation, see this article.

Limitations

There are some limitations that come with formula-based conditional formatting:

  1. You can’t apply icons, color scales, or data bars with a custom formula. You are limited to standard cell formatting, including number formats, font, fill color and border options.
  2. You can’t use certain formula constructs like unions, intersections, or array constants for conditional formatting criteria.
  3. You can’t reference other workbooks in a conditional formatting formula.

You can sometimes work around #2 and #3. You may be able to move the logic of the formula into a cell in the worksheet, then refer to that cell in the formula instead. If you are trying to use an array constant, try created a named range instead.

Источник

In this article we will learn how to color rows based on text criteria we use the “Conditional Formatting” option. This option is available in the “Home Tab” in the “Styles” group in Microsoft Excel.

Conditional Formatting in Excel is used to highlight the data on the basis of some criteria. It would be difficult to see various trends just for examining your Excel worksheet. Conditional Formatting in excel provides a way to visualize data and make worksheets easier to understand.

Excel Conditional Formatting allows you to apply formatting basis on the cell values such as colors, icons and data bars. For this, we will create a rule in  excel Conditional Formatting based on cell value

How to write an if statement in excel?
IF function is used for logic_test and returns value on the basis of the result of the logic_test. Excel conditional formatting formula multiple conditions uses Statements like less than or equal to or greater than or equal to the value are used in IF formula

Syntax:

=IF (logical_test, [value_if_true], [value_if_false])

Let’s learn how to do conditional formatting in excel using IF function with the example.

Here is a list of Names and their respective Scores.

IF 1

multiple if statements excel functions are used here. So, there are 3 results based on the condition. if then statements in excel is used via excel conditional formatting formula

Write the formula in C2 cell.
Formula

=IF(B2<50,»C»,IF(B2<75,»B»,»A»))

Explanation:
IF function only returns 2 results, one [value_if_True] and Second [value-if_False]
First IF function checks, if the score is less than 50, would get C grade, The Second IF function tests if the score is less than 75 would get B grade and the rest A grade.

IF 2

Copy the formula in other cells, select the cells taking the first cell where the formula is already applied, use shortcut key Ctrl + D

IF 3

Now we will apply conditional formatting to it.

Select Home >Conditional Formatting > New Rule.

IF 4

A dialog box appears

IF 5

Select Format only cells that contain > Specific text in option list and write C as text to be formatted.

Fill Format with Red colour and click OK.

Now select the colour Yellow and Green for A and B respectively as done above for C.

IF 6

In this article, we used IF function and Conditional formatting tool to get highlighted grade.

As you can see excel change cell color based on value of another cell using IF function and Conditional formatting tool

Hope you learned how to use conditional formatting in Excel using IF function. Explore more conditional formulas in excel here. You can perform Conditional Formatting in Excel 2016, 2013 and 2010. If you have any unresolved query regarding this article, please do mention below. We will help you.

Related Articles:

How to use the Conditional formatting based on another cell value in Excel

How to use the Conditional Formatting using VBA in Microsoft Excel

How to use the Highlight cells that contain specific text in Excel

How to Sum Multiple Columns with Condition in Excel

Popular Articles:

50 Excel Shortcut to Increase Your Productivity

How to use the VLOOKUP Function in Excel

How to use the COUNTIF function in Excel 2016

How to use the SUMIF Function in Excel

Conditional Formatting is one of the most simple yet powerful features in Excel Spreadsheets.

As the name suggests, you can use conditional formatting in Excel when you want to highlight cells that meet a specified condition.

It gives you the ability to quickly add a visual analysis layer over your data set. You can create heat maps, show increasing/decreasing icons, Harvey bubbles, and a lot more using conditional formatting in Excel.

Using Conditional Formatting in Excel (Examples)

In this tutorial, I’ll show you seven amazing examples of using conditional formatting in Excel:

  • Quickly Identify Duplicates using Conditional Formatting in Excel.
  • Highlight Cells with Value Greater/Less than a Number in a Dataset.
  • Highlighting Top/Bottom 10 (or 10%) values in a Dataset.
  • Highlighting Errors/Blanks using Conditional Formatting in Excel.
  • Creating Heat Maps using Conditional Formatting in Excel.
  • Highlight Every Nth Row/Column using Conditional Formatting.
  • Search and Highlight using Conditional Formatting in Excel.
1. Quickly Identify Duplicates

Conditional formatting in Excel can be used to identify duplicates in a dataset.

Here is how you can do this:

This would instantly highlight all the cells that have a duplicate in the selected data set. Your dataset can be in a single column, multiple columns, or in a non-contiguous range of cells.

Conditional Formatting in Excel - Single Multiple Columns

See Also: The Ultimate Guide to Find and Remove Duplicates in Excel.
2. Highlight Cells with Value Greater/Less than a Number

You can use conditional formatting in Excel to quickly highlight cells that contain values greater/less than a specified value. For example, highlighting all cells with sales value less than 100 million, or highlighting cells with marks less than the passing threshold.

Here are the steps to do this:

This would instantly highlight all the cells with values greater than 5 in a dataset.Conditional Formatting in Excel - greater than 5 highlightedNote: If you wish to highlight values greater than equal to 5, you should apply conditional formatting again with the criteria “Equal To”.

The same process can be followed to highlight cells with a value less than a specified values.

3. Highlighting Top/Bottom 10 (or 10%)

Conditional formatting in Excel can quickly identify top 10 items or top 10% from a data set. This could be helpful in situations where you want to quickly see the top candidates by scores or top deal values in the sales data.

Similarly, you can also quickly identify the bottom 10 items or bottom 10% in a dataset.

Here are the steps to do this:

This would instantly highlight the top 10 items in the selected dataset. Note that this works only for cells that have a numeric value in it.

Also, if you have less than 10 cells in the dataset, and you select the options to highlight Top 10 items/Bottom 10 Items, then all the cells would get highlighted.

Here are some examples of how the conditional formatting would work:

Conditional Formatting in Excel - Top bottom example

4. Highlighting Errors/Blanks

If you work with a lot of numerical data and calculations in Excel, you’d know the importance of identifying and treating cells that have errors or are blank. If these cells are used in further calculations, it could lead to erroneous results.

Conditional Formatting in Excel can help you quickly identify and highlight cells that have errors or are blank.

Suppose we have a dataset as shown below:

Conditional Formatting in Excel - Error dataset

This data set has a blank cell (A4) and errors (A5 and A6).

Here are steps to highlight the cells that are empty or have errors in it:

This would instantly highlight all the cells that are either blank or have errors in it.

Conditional Formatting in Excel - errors highlightedNote: You don’t need to use the entire range A1:A7 in the formula in conditional formatting. The above-mentioned formula only uses A1. When you apply this formula to the entire range, excel checks one cell at a time and adjusts the reference. For example, when it checks A1, it uses the formula =OR(ISBLANK(A1),ISERROR(A1)). When it checks cell A2, it then uses the formula =OR(ISBLANK(A2),ISERROR(A2)). It automatically adjusts the reference (as these are relative references) depending on which cell is being analyzed. So you need not write a separate formula for each cell. Excel is smart enough to change the cell reference all by itself 🙂

See Also: Using IFERROR and ISERROR to handle errors in excel.
5. Creating Heat Maps

A heat map is a visual representation of data where the color represents the value in a cell. For example, you can create a heat map where a cell with the highest value is colored green and there is a shift towards red color as the value decreases. 

Something as shown below:

Conditional Formatting in Excel - heatmap

The above data set has values between 1 and 100. Cells are highlighted based on the value in it. 100 gets the green color, 1 gets the red color.

Here are the steps to create heat maps using conditional formatting in Excel.

  • Select the data set.
  • Go to Home –> Conditional Formatting –> Color Scales, and choose one of the color schemes.Conditional Formatting in Excel - heatmap colors

As soon as you click on the heatmap icon, it would apply the formatting to the dataset. There are multiple color gradients that you can choose from. If you are not satisfied with the existing color options, you can select more rules and specify the color that you want.

Note: In a similar way, you can also apply Data Bard and Icon sets.

6. Highlight Every Other Row/Column

You may want to highlight alternate rows to increase the readability of the data.

These are called the zebra lines and could be especially helpful if you are printing the data.

Now there are two ways to create these zebra lines. The fastest way is to convert your tabular data into an Excel Table. It automatically applied a color to alternate rows. You can read more about it here.

Another way is using conditional formatting.

Suppose you have a dataset as shown below:

Conditional Formatting in Excel - Alternate Data

Here are the steps to highlight alternate rows using conditional formatting in Excel.

That’s it! The alternate rows in the data set will get highlighted.

Conditional Formatting in Excel - Alternate rows final

You can use the same technique in many cases. All you need to do is use the relevant formula in the conditional formatting. Here are some examples:

  • Highlight alternate even rows: =ISEVEN(ROW())
  • Highlight alternate add rows: =ISODD(ROW())
  • Highlight every 3rd row: =MOD(ROW(),3)=0
7. Search and Highlight Data using Conditional Formatting

This one is a bit advanced use of conditional formatting. It would make you look like an Excel rockstar.

Suppose you have a dataset as shown below, with Products Name, Sales Rep, and Geography. The idea is to type a string in cell C2, and if it matches with the data in any cell(s), then that should get highlighted. Something as shown below:

Conditional formatting in Excel - search and highlight demo

Here are the steps to create this Search and Highlight functionality:

That’s it! Now when you enter anything in cell C2 and hit enter, it will highlight all the matching cells.

How does this work?

The formula used in conditional formatting evaluates all the cells in the dataset. Let’s say you enter Japan in cell C2. Now Excel would evaluate the formula for each cell.

The formula would return TRUE for a cell when two conditions are met:

  • Cell C2 is not empty.
  • The content of cell C2 exactly matches the content of the cell in the dataset.

Hence, all the cells that contain the text Japan get highlighted.

Download the Example File
Download File

You can use the same logic, to create variations such as:

  • Highlight the entire row instead of a cell.
  • Highlight even when there is a partial match.
  • Highlight the cells/rows as you type (dynamic) [You are going to love this trick :)].

How to Remove Conditional Formatting in Excel

Once applied, conditional formatting remains in place unless you remove it manually. As a best practice, keep the conditional formatting applied only to those cells where you need it.

Since it’s volatile, it may lead to a slow Excel workbook.

To remove conditional formatting:

  • Select the cells from which you want to remove conditional formatting.
  • Go to Home –> Conditional Formatting –> Clear Rules –> Clear Rules from Selected Cells.
    • If you want to remove conditional formatting from the entire worksheet, select Clear Rules from Entire Sheet.Conditional Formatting in Excel - Clear Rules
Important things to know about Conditional Formatting in Excel
  • Conditional formatting in volatile. It can lead to a slow workbook. Use it only when needed.
  • When you copy paste cells that contain conditional formatting, conditional formatting also gets copied.
  • If you apply multiple rules on the same set of cells, all rules remain active. In the case of any overlap, the rule applied last is given preference. You can, however, change the order by changing the order from the Manage Rules dialogue box.

You May Also Like the Following Excel Tutorials:

  • The Right Way to Apply Conditional Formatting in Pivot Table
  • Find and Remove Duplicates in Excel
  • The Ultimate Guide to Using Conditional Formatting in Google Sheets
  • How to Highlight Weekend Dates in Excel?

This tutorial demonstrates how to apply conditional formatting based on a cell value or text in Excel and Google Sheets.

CondFormat Values intro

Excel has a number of built-in Conditional Formatting rules that can be used to format cells based on the value of each individual cell.

Highlight Cells Rules

Perhaps the most straightforward set of built-in rules simply highlights cells containing values or text that meet criteria you define.

  1. Select the cells where you want to highlight certain values.

CondFormat Values select cells

  1. Then, in the Ribbon, select Home > Conditional Formatting > Highlight Cells Rules.
    The Highlight Cells Rules category allows you to select from greater than, less than, or equal to a certain value; between two set values; containing a text string; relating to a certain date; or containing a duplicated value.

CondFormat Values highlight cell rules

  1. For this example, select Greater Than… and then type in the target number, where you want cells greater than that target highlighted, and select a format.

CondFormat Values greater than

Note: Instead of typing in the actual value in the Format cells that are GREATER THAN box, you can click on a cell in your worksheet where you have a value stored. This would mean that if the value in that cell on your worksheet changed, the conditional formatting would change.

  1. Click OK.

CondFormat Values formatted

Highlight Cells With Text

You can also test whether a cell contains a certain word or string of text using Highlight Cells Rules.

  1. Once again, select the cells where you want to highlight based on text.
  2. Then, in the Ribbon, select Home > Conditional Formatting > Highlight Cells Rules > Text that Contains…

condformat values text that contains

  1. Type in your target text and select a format.

condformat values text

  1. Click OK.

Note: you can also type in part of a word or part of the text that is in the cell, you do not have to match the text entirely so typing as, for example, finds the cell with Texas in it.

Custom Rule

  1. In addition to these built-in Highlight Cells Rules, you can also create a custom rule by clicking on the More Rules… option at the bottom of the Highlight Cells Rules menu.

condformat values more rules

  1. Format only cells that contain is already highlighted. For this example, in the Format only cells with drop-down box, select Blanks.
  2. Then click Format

condformat values blanks

  1. In the Format Cells window, choose a fill color, and press OK.

condformat values format

  1. Click OK once again to apply the conditional formatting to your cells.

condformat values format blanks

Top/Bottom Rules

Top and bottom rules allow you to format cells according to the top or bottom values in a range. These rules only work on cells that contain values (not text!).

  1. Select the range where you want to highlight the highest or lowest values.
  2. Then, in the Ribbon, select Home > Conditional Formatting > Top/Bottom Rules.

CondFormat Values top bottom

The Top/Bottom Rules category allows you to select from Top 10 Items, Top 10%, Bottom 10 Items, Bottom 10%, Above Average, or Below Average.

  1. For this example, select Bottom 10%…
  2. Adjust the target percentage up or down as needed, and then select a format. Click OK to apply the format to selected cells.

CondFormat Values bottom10%

Note that you could also select Above Average or Below Average. These rules automatically calculate the mean of your data range and format cells either greater than or less than that value.

conform values above average

  1. To customize your rule even further, go back to the Top/Bottom Rules menu (from Step 2), and click More Rules… at the bottom.
  1. The rule type is selected for you (Format only top or bottom ranked values).
    You can then edit the rule description by selecting either Top or Bottom in the drop-down list, and then typing in the comparison value (for example, 25, as shown below).
    Check the % of the selected range if you want the top percentage of the values formatted rather than the actual top 25 values formatted.

condformat values custom topbottom

  1. Set the format (see Steps 4 and 5 in the “Custom Rule” section), and then click OK to return to Excel.

Data Bars

Data-bars rules add bars to each cell. The higher the value in the cell, the longer the bar is. These rules only work on cells that contain values (not text!).

  1. Select the cells where you want to show data bars.
  2. Then, in the Ribbon, select Home > Conditional Formatting > Data Bars.

conformat values data bars

Data-bars rules allow you to select either a Gradient Fill or a Solid Fill bar in a variety of colors.

  1. To insert data bars into your cells, click on your preferred option.

condformat values data bars fill

  1. To customize your rule even further, click More Rules… at the bottom of the Data Bars menu.
  2. The rule type is selected for you (Format all cells based on their values). For this example, check Show Bar Only, and then select the bar appearance (gradient or solid color). You can also choose to add border and choose the direction of the bars.

format show bar only

  1. Click OK to apply the formatting to selected cells.

CondFormat Values data bars no numbers

Color Scales

Color-scales rules format cells according to their values relative to a selected range.

  1. Select the cells where you want to apply color scales.
  2. Then, in the Ribbon, select Home > Conditional Formatting > Color Scales.

CondFormat Values color scales

  1. To add a color scale to your cells, click on your preferred option.

CondFormat Values color scales select

  1. To customize your rule even further, click More Rules… at the bottom of the Color Scales menu.
  2. The rule type is selected for you (Format all cells based on their values). Select a format style (either 2- or 3-color scale) and then set the values and colors you want.

CondFormat Values color scales custom

  1. Click OK to apply the formatting to your selected cells.

condfomat values format bars

Icon Sets

There is one more built-in set of rules called Icon Sets. Click the link to learn about adding icon sets to your data.

Format Based on Value or Text in Google Sheets

There are only two types of conditional formatting in Google Sheets: Single color and Color scale. Google Sheets’s Single color rules are similar to Highlight Cells Rules in Excel. Color scales rules are similar in the two applications as well.

Single Color

  1. Highlight the cells you wish to format, and then in the Menu, select Format > Conditional formatting.

condformat values gs menu

  1. In the format rules drop-down box, there is a long list of formats you can apply. For this example, select greater than.

condformat values gs condformat

  1. Type in the comparison value, and then click on the format drop down to select a fill color.

condformat values gs format

  1. Finally, click on Done to apply the formatting to selected cells.

condformat values gs formatted

Color Scale

  1. To set a Color scale rule, click on Color scale in the Conditional formatting menu. In the format rules box, select an option to preview.

condformat values gs format rules

  1. You can then customize the Minpoint, Midpoint, and Maxpoint if you wish, or leave the default values.

condformat values gs color scale rules

  1. Click Done to apply the formatting to your selected cells.

condformat values gs color scale formatted

Explanation

Conditional Formatting lets the user apply formatting to a cell or a range of cells based on specific criteria.

There are various conditions that can be tested in order to apply the formatting:

  • Format cells based on their values
  • Format cells that contain a certain text
  • Format top/bottom-ranked cells in a range
  • Format duplicates
  • Format cells based on a formula
  • And much more!

Basic Usage

To use conditional formatting, select the cell/range of cells that you would like to format. 

Then, from the Home tab, select “Conditional Formatting”:

Conditional Formatting Examples

Formatting cells based on their values

We can format cells based on their values using Conditional Formatting. 

For example, this is how we tell Excel to change the background color of all values greater than 60 to green:

First, let’s select the range we’d like to format:

Next, click on Conditional Formatting – Highlight Cells Rules – Greater Than:

Now, in the value type “60”, and select “Green Fill with Dark Green Text”:

And here’s the final result:

Note – If you want to apply a style that doesn’t appear in the basic menu, just select “Custom Format”:

Format cells if their text contains a certain text

Now, let’s see how we can format only the cities which contain the text “ster”:

We can do it by clicking Conditional Formatting – Highlight Cells Rules – Text That Contains:

Formatting top/bottom cells in a range

We can quickly find top/bottom cells using Conditional Formatting.

How can we format the Top 10% of students’ test scores?

To do this, select Conditional Formatting – Top/Bottom Rules – Top 10%:

Formatting Duplicate Cells

We can quickly understand which cells are duplicates within our range using Conditional Formatting – Highlight Cells Rules – Duplicate Values.

Let’s see how can find all the duplicate cities in the following table:

Tip – If you wish to remove duplicates, use the “Remove Duplicates” tool – Click here to read the tutorial!

Format Cells Based on a Formula

This is probably the most powerful feature of Conditional Formatting – We can apply any formula we want as a condition!

Now, Let’s see how we can highlight all cells that contain more than 6 characters.

To do so, we can use the LEN formula to calculate the number of characters in each cell.

So, let’s select Conditional Formatting – Highlight Cells Rules – More Rules – Use a formula to determine which cells to format:

Please note – within the LEN formula, we select only one of the cells in the range. Please make sure that the cell does not have any reference (absolute or partial) to allow the formula to adjust itself to each of the cells in the range. More about absolute/partial references can be found in our Excel Basics guide.

Format using a Color Scale

We can apply a Color Scale on our cells, for example – if we want to quickly identify the hottest temperatures (Hotter – Red, Colder – Green). 

Just Select Conditional Formatting – Color Scales – Select the desired Color Scale:

Now, let’s practice Conditional Formatting. Click here to download the Conditional Formatting exercise for free!

Ezoic

The best part of conditional formatting is you can use formulas in it. And, it has a very simple sense to work with formulas.

Your formula should be a logical formula and the result should be TRUE or FALSE. If the formula returns TRUE, you’ll get the formatting, and if FALSE then nothing. The point is, by using formulas you can make the best out of conditional formatting.

Yes, that’s right. In the below example, we have used a formula in CF to check whether the value in the cell is smaller than 1000 or not.

use formulas in conditional formatting to check if value is greater

And if that value is smaller than 1000 it will apply the formatting which we have specified, otherwise not. So today in this post, I’d like to share with you simple steps to apply conditional formatting using a formula. And some of the useful examples that you can use in your daily work.

Steps to Apply Conditional Formatting with Formulas

The steps to apply CF with formulas are quite simple:

  1. Select the range to apply Conditional Formatting.
  2. Add a formula to text a condition.
  3. Specify a format to apply when the condition is met.
how to apply conditional formatting using a formula

To learn this in a proper way make sure to download this sample file from here and follow the below-detailed steps.

  • First of all, select the range where you want to apply conditional formatting.
to apply conditional formatting using formulas select range
  • After that, go to Home Tab ➜ Styles ➜ Conditional Formatting ➜ New Rule ➜ Use a formula to determine which cell to format.
to apply conditional formatting using formulas click on new rule
  • Now, in the “Format values where formula is true” enter the below formula.

=E5<1000

to apply conditional formatting using formulas enter formula
  • The next thing is to specify the format to apply and for this, click on the format button and select the format.
to apply conditional formatting using formulas specify formatting
  • In the end, click OK.

While entering a formula in the CF dialog box you can’t see its result or whether that formula is valid or not. So, the best practice is to check that formula before using it in CF by entering it in a cell.

    1. Use a Formula that is Based on Another Cell

    Yes, you can apply conditional formatting based on another cell’s value. If you look at the below example, we have added a simple formula that is based on another cell. And if the value of that linked cell meets the condition specified, you’ll get conditional formatting.

    apply conditional formatting with a formula using another cell

    When achievement will be below 75%, it will highlight in red color.

    apply conditional formatting with a formula using another cell with percentage 75

    2. Conditional Formatting using IF

    Whenever I think about conditions, the first thing that comes to my mind is using the IF function. And the best part of this function is, that it fits perfectly in conditional formatting. Let me show you an example:

    using formulas to apply conditional formatting with if

    Here, we have used the IF to create a condition and the condition is when the count of “Done” in range B3:B9 is equal to the count of tasks in the range A3:A9, then the final status will appear.

    this formula in conditional formatting will format cell when all the tasks are done

    2. Conditional Formatting with Multiple Conditions

    You can create multiple checks in conditions to apply to the format. Once all the conditions or one of the conditions will meet, conditional formatting will apply to the cell. Look at the below example where we have used the average temperature of my town.

    And we have used a simply combined IF-AND to highlight the months when the temperature is pretty pleasant. Months where the temperature is between 15 Celsius to 35 Celsius, will get colored.

    use if and formula in conditional formatting to highlight cell with temperatures

    Just like this, you can also use if with or function.

    4. Highlight Alternate Rows with Conditional Formatting

    To highlight every alternate row you can use the following formula n CF.

    =INT(MOD(ROW(),2))

    By using this formula, every row whose number is odd will be highlighted. And, if you want to do vice versa you can use the following formula.

    table with highlighted alternate rows using formula in conditional formatting

    =INT(MOD(ROW()+1,2))

    The same kind of formula can use for columns (odd and even) as well.

    =INT(MOD(COLUMN(),2))

    And for even columns.

    =INT(MOD(COLUMN()+1,2))

    use conditional formatting highlight column alternate

    5. Highlight Cells with Errors using CF

    Now let’s come to another example where we will check whether a cell contains an error or not. What we need to do is just insert a formula in conditional formatting that can check the condition and return the result in TRUE or FALSE. You can even verify cells for numbers, text, or some specific values as well.

    highlight errors from cells using conditional formatting

    6. Create a Checklist with Conditional Formatting

    Now let’s add some creativity to intelligence. You have already learned how to use a formula that is based on another cell. Here we have linked a checkbox with the B1 cell and further linked the B1 with the formula used in conditional formatting for cell A1.

    checklist using conditional formatting and checkbox

    Now, if you tick mark the checkbox, the value of cell B1 will turn into TRUE and cell A1 gets it conditional formatting [strikethrough].

    a dynamic checklist using formulas in conditional formatting

    Points to Remember

    1. Your formula should be a logical formula, which leads to a result as TRUE or FALSE.
    2. Try not to overload your data with conditional formatting.
    3. Always use relative and absolute references in a proper sense.

    Sample File

    Download this sample file from here to learn more.

    More Tutorials

    • AUTO FORMAT Option in Excel
    • Apply Accounting Number Format in Excel
    • Apply Background Color to a Cell or the Entire Sheet in Excel
    • Print Excel Gridlines
    • Add Page Number in Excel
    • Apply Comma Style in Excel
    • Apply Strikethrough in Excel
    • Highlight Blank Cells in Excel
    • Make Negative Numbers Red in Excel
    • Cell Style (Title, Calculation, Total, Headings…) in Excel
    • Change Date Format in Excel
    • Highlight Alternate Rows in Excel with Color Shade
    • Use Icon Sets in Excel (Conditional Formatting)
    • Add Border in Excel
    • Change Border Color in Excel
    • Clear Formatting in Excel
    • Copy Formatting in Excel
    • Best Fonts for Microsoft Excel
    • Hide Zero Values in Excel

    ⇠ Back to Advanced Excel Tutorials

    Combine conditional formatting with an IF statement

    Syntax 

    =IF (logical_test, [value_if_true], [value_if_false])

    But in conditional formatting, IF/THEN/ELSE syntax cannot be applied in a single rule. Conditional formatting is applied using IF/THEN logical test only. It must return TRUE for conditional formatting to be applied.

    For example, if you want to apply conditional formatting using a condition that “If a cell value is greater than a set value, say 100, then format the cell as RED, else format the cell as GREEN”. So, you can see that it requires two rules to perform the conditional formatting, one for greater than 100, and one for less than 100.

    You can apply more than one condition by creating more than one rule in conditional formatting. You can also use logical functions like AND and OR to create a rule set and apply conditional formatting in Excel.

    Examples using conditional formatting with IF/THEN conditions

    Let’s look at the scenarios to see how to use IF/THEN logical test in conditional formatting to highlight the targeted values. If you want to highlight the invoices in data range of A2:C13 which are due in the month of April, then you need to test the IF/THEN logical condition on date range in column B, if the month is equal to April, by using following custom formula in conditional formatting.=MONTH($B2)=4

    First, select the data range A2:C13, then go to:

    Conditional Formatting (on the Home tab) > New Rule> Use a formula to determine…> Enter the above formula in Edit Rule Description window> Choose the Format Fill to preview and press OK

    How to Combine Conditional Formatting with an IF Statement

    Please note that you have to fix the column by making it absolute using $ sign with it, and keep the row number free or relative to change. Hence, the formula will check each row of the specified column in the selected range, test the IF/THEN logical condition and will return TRUE and FALSE.

    This rule will be evaluated in all active cells of locked column B one by one ignoring other cells in columns A and C. When the MONTH function in a cell of column B returns number 4 (April), the rule will return TRUE for all the active cells in that row and conditional formatting will be applied to that entire row as shown below.

    How to Combine Conditional Formatting with an IF Statement

    Now, if you want to conditionally highlight the two largest amount invoices due in the month of April, then you can achieve this by creating a rule set based on array formula using AND, LARGE and IF statement as per the following syntax.

    =AND(criteria,$C2>=LARGE (IF(criteria, values),2)) =AND(MONTH($B2)=criteria,$C2>=LARGE (IF(MONTH(date)=criteria, amount),2)) =AND(MONTH($B2)=4,$C2>=LARGE(IF(MONTH($B$2:$B$13)=4,$C$2:$C$13),2))

    By applying this custom formula, you can highlight the two largest amount invoices in the month of April. LARGE with IF function will generate a series of values and compare them with each value in column C. AND function will test the logical conditions in each cell of column B and C both one by one and will return TRUE where both conditions will be met. Have a look below.

    How to Combine Conditional Formatting with an IF Statement

    Need some additional help with Conditional Formatting or have other questions about Excel? Connect with a live Excel expert here for some 1 on 1 help. Your first session is always free. 

    Are you still looking for help with the Average function? View our comprehensive round-up of Average function tutorials here.

    When you want to format a cell based on the value of a different cell, for example to format a report row based on a single column’s value, you can use the conditional formatting feature to create a formatting formula. This post explores the details of formatting a cell or range based on the value in another cell.

    Objective

    Here’s an example that will allow us to put this feature into context. Let’s say that you have an invoice listing and your objective is to identify the open invoices. Here is a screenshot of our sample invoice listing:

    20131212e

    Since this is Excel, there are many ways to accomplish any given task. One way to identify the open invoices is to simply sort the list by the Status column so that the open invoices appear in a group. Another way is to filter the listing to show only the open invoices. These techniques are fairly straightforward, so, let’s explore another method. We’ll highlight the transaction rows with cell formatting…or, more precisely, a conditional formatting formula.

    Video

    Conditional Formatting Narrative

    Using conditional formatting, it would be pretty easy to highlight just the Status column. It would be simple because the cells we are formatting are the same cells that have the values to evaluate. That is, we would be formatting a cell based on the value within that cell. To perform this, we could simply highlight the Status column, and the use the following Ribbon command:

    • Home > Conditional Formatting > Cell Rules > Equal To

    In the Equal To dialog box, we could enter the word “Open” and pick the desired formatting and click OK. Excel would then apply the formatting to the cells within the Status column that are equal to Open. While this technique is easy, it does not meet our goal which is to highlight the entire transaction row, not just the Status column.

    To highlight the entire transaction row requires us to format a cell based on the value in another cell. That is, we want to format the TID, Date, Status, CustID, and Amount columns based on the value in the Status column. Considering a single cell for a moment, we want to format B7 based on the value in D7. This means that we want to format a cell, B7, based on the value in a different cell, D7. Expanding this to the entire row, we want to format B7:F7 based on the value in D7.

    Excel makes it easy for users to format a cell based on the value of that cell, and the built-in conditional formatting rules use this logic. When we want to format a cell based on the value in a different cell, we’ll need to use a formula to define the conditional formatting rule. Fortunately, it is not very difficult to set up such a formatting formula.

    Let’s highlight the entire transaction listing (B7:F36) first, and then open the conditional formatting dialog box using the following Ribbon icon:

    • Home > Conditional Formatting > New Rule

    20131212b

    The New Formatting Rule dialog box has many choices, allowing you to, for example, format a cell based on the value, if it contains a value, the top or bottom ranked values, values that are above or below average, and unique or duplicate values. At the bottom of the list we find the option we need. We want to use a formula to determine which cells to format.

    The formatting formula needs to be set up so that it returns a true or false value. If the formula returns true, then the desired formatting is applied. If the formula returns false, the formatting is not applied.

    The key thing to understand about writing the formula is that the active cell is the reference point for the formula. Since this concept is absolutely critical, I don’t want to just skip through it, I want to unpack it for a moment.

    You want to write the formatting formula as if you are writing it into the active cell and use the appropriate cell references and reference styles, such as absolute, relative, and mixed. If you can visualize the idea that you are writing the formula into the active cell, and the formula will be filled through the selected range, then writing the formula becomes easier. The formula you write will not be used to compute the cell value, rather, it will be used only for formatting.

    Let’s assume that when we selected the entire transaction range, B7:F36 that the active cell is B7. When you select a range, there is still a single active cell. Check out the screenshot below to see that the range is selected, yet, B7 remains the active cell:

    20131212d

    With this idea in mind, it is easy to write the conditional formatting formula now. We need to write the following formula in the New Formatting Rule dialog, as if we were writing it into cell B7:

    =$D7="Open"

    This simple comparison formula returns true when D7 is equal to Open, and thus, the desired format will be applied. Let’s take a quick look at the cell reference for a moment. We used a mixed cell reference, $D7, where the column part (D) is absolute and the row part (7) is relative. Here’s why. Remember we want to pretend that we are writing the formula into the active cell, in this case, B7. If we were only formatting B7, then, we could have used a relative reference D7, or an absolute reference $D$7, or a mixed reference. The reference style wouldn’t matter because the formula was used in a single cell only and was not filled anywhere.

    However, the moment that we fill a formula down or to the right, we need to be careful to use the proper cell reference styles. In our case, as the formatting formula is filled right, we don’t want the column reference D to change. That is, for all cells, we want to reference the Status column, column D. To prevent Excel from changing the column reference as the formula is filed to the right, we lock it down with the dollar sign, resulting in $D. As the formatting formula is filled down throughout the selected range, we want to ensure that the row reference is updated accordingly. When formatting B7, we want to look at the Status column within the same row, or D7. However, when the formula is filled down to row 8, we want to format B8 based on the value in D8. Since we want Excel to update the row reference, we’ll leave it relative and not use the dollar sign to lock it down.

    Here is a screenshot of the formatting dialog box with the formula:

    20131212f

    Once the formula is entered, you simply use the Format button to specify the desired format.

    Once the conditional formatting is applied to the range, the resulting worksheet is shown below:

    20131212g

    Bam…we got it!


    FREE: Excel Speed Challenge

    If you enjoyed this post, please check out our free Excel speed challenge.

    Watch one short Excel video a day for 5 days. Total video time is only 45 minutes. Learn the Excel skills that can help you save an hour a week.


    Other Considerations

    In the formula above, we hard-coded the value, “Open” however, we could have easily placed this value into a cell, and then referenced the cell either by name or A1-style notation. In addition, besides just determining if the cell value is equal to a value, other comparison operators are supported, for example, greater than (>) and less than (<). We could have highlighted all rows where the value is greater than $5,000 by using the following comparison formula:

    =$F7>5000

    Since the formatting is applied based on a formula, we can get very creative and use worksheet functions. We could format alternating worksheet rows by using the MOD and ROW functions. Or, we could highlight old transactions by computing the difference between the transaction date and today’s date with the TODAY function. Indeed, this formatting formula provides many fun options.

    Multiple Conditions

    We can also use the logical AND and OR functions in case we want to consider multiple conditions. For example, formatting those rows where the status is open and the amount is greater than 5000 by using the following formula:

    =AND($D7="Open",$F7>5000)

    Since the AND function returns true when all of its arguments are true, the formatting is applied only when the status is open and the amount is greater than 5,000.

    If we wanted to format the row if either condition was met, then we’d want to use the OR function instead of the AND function since it returns true if any single argument is true.

    Conclusion

    Having the ability to format a cell based on the value of another cell is quite handy. The key is to imagine that you are writing a formula into the active cell. The formula needs to use the appropriate cell reference styles (absolute, relative, mixed) so that as the formatting formula is filled throughout the selected range, the proper cells are considered. The sample file below has the conditional formatting rules included, so feel free to check it out.

    Hope this helps, and remember, Excel rules!

    Sample File

    Here is the sample file in case you’d like to open it up and reference it.

    FormattingFormula

    Понравилась статья? Поделить с друзьями:
  • Excel format cell date format
  • Excel format cell as string
  • Excel format as percent
  • Excel format as datetime
  • Excel format all columns