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.
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.
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 |
|
Scoping by value field |
|
Scoping by corresponding field |
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:
|
Note: Quick Analysis is not available in Excel 2010 and previous versions.
Use the Quick Analysis button to apply selected conditional formatting to the selected data. The Quick Analysis button appears automatically when you select data.
-
Select the data that you want to conditionally format. The Quick Analysis button appears on the lower-right corner of the selection.
-
Click the Quick Analysis button , or press Ctrl+Q.
-
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.
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.
-
-
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.
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
-
Select one or more cells in a range, table, or PivotTable report.
-
On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Color Scales.
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
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.
-
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:
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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>.
-
-
Under Select a Rule Type, click Format all cells based on their values (default).
-
Under Edit the Rule Description, in the Format Style list box, select 2-Color Scale.
-
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.
-
-
-
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
On the Home tab, in the Styles group, click the arrow next to Conditional Formatting, and then click Color Scales.
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
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.
-
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:
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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.
-
-
Under Select a Rule Type, click Format all cells based on their values.
-
Under Edit the Rule Description, in the Format Style list box, select 3-Color Scale.
-
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.
-
-
-
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.
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
-
Select one or more cells in a range, table, or PivotTable report.
-
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.
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
-
Select one or more cells in a range, table, or PivotTable report.
-
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.
-
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:
-
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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.
-
-
Under Select a Rule Type, click Format all cells based on their values.
-
Under Edit the Rule Description, in the Format Style list box, select Data Bar.
-
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.
-
-
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.
-
To show only the data bar and not the value in the cell, select Show Bar Only.
-
To apply a solid border to data bars, select Solid Border in the Border list box and choose a color for the border.
-
To choose between a solid bar and a gradiated bar, choose Solid Fill or Gradient Fill in the Fill list box.
-
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.
-
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.
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
-
Select the cells that you want to conditionally format.
-
On the Home tab, in the Style group, click the arrow next to Conditional Formatting, click Icon Set, and then select an icon set.
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
-
Select the cells that you want to conditionally format.
-
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.
-
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:
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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.
-
-
Under Select a Rule Type, click Format all cells based on their values.
-
Under Edit the Rule Description, in the Format Style list box, select Icon Set.
-
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.
-
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.
-
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.
-
-
-
To make the first icon represent lower values and the last icon represent higher values, select Reverse Icon Order.
-
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.
Note: You cannot conditionally format fields in the Values area of a PivotTable report by text or by date, only by number.
Quick formatting
-
Select one or more cells in a range, table, or PivotTable report.
-
On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules.
-
Select the command you want, such as Between, Equal To Text that Contains, or A Date Occurring.
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
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.
-
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:
-
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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.
-
-
Under Select a Rule Type, click Format only cells that contain.
-
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!.
-
-
To specify a format, click Format. The Format Cells dialog box appears.
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Top/Bottom Rules.
-
Select the command you want, such as Top 10 items or Bottom 10 %.
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
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.
-
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:
-
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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.
-
-
Under Select a Rule Type, click Format only top or bottom ranked values.
-
Under Edit the Rule Description, in the Format values that rank in the list box, select Top or Bottom.
-
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.
-
-
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.
-
-
To specify a format, click Format. The Format Cells dialog box appears.
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Top/Bottom Rules.
-
Select the command you want, such as Above Average or Below Average.
-
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
-
Select one or more cells in a range, table, or PivotTable report.
-
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.
-
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:
-
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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.
-
-
Under Select a Rule Type, click Format only values that are above or below average.
-
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.
-
-
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.
-
-
Click Format to display the Format Cells dialog box.
-
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.
Quick formatting
-
Select the cells that you want to conditionally format.
-
On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules.
-
Select Duplicate Values.
-
Enter the values you want to use, and then select a format.
Advanced formatting
-
Select the cells that you want to conditionally format.
-
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.
-
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:
-
-
Make sure that the appropriate worksheet or table is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
Under Select a Rule Type, click Format only unique or duplicate values.
-
Under Edit the Rule Description, in the Format all list box, select unique or duplicate.
-
Click Format to display the Format Cells dialog box.
-
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.
-
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.
-
Select the duplicate rule, then select Edit Rule.
-
Select the cells that you want to format.
-
On the Home tab, click Conditional Formatting > New Rule.
-
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.
-
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.
-
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:
-
-
Make sure that the appropriate worksheet, table, or PivotTable report is selected in the Show formatting rules for list box.
-
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.
-
Select the rule, and then click Edit rule. The Edit Formatting Rule dialog box appears.
-
-
-
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>.
-
-
Under Select a Rule Type, click Use a formula to determine which cells to format.
-
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).
-
Click Format to display the Format Cells dialog box.
-
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))
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.
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.
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.
-
Click the cell that has the conditional formatting that you want to copy.
-
Click Home > Format Painter.
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.
-
To paste the conditional formatting, drag the paintbrush across the cells or ranges of cells you want to format.
-
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
-
Click any cell that does not have a conditional format.
-
On the Home tab, in the Editing group, click the arrow next to Find & Select, and then click Conditional Formatting.
Find only cells that have the same conditional format
-
Click any cell that has the conditional format that you want to find.
-
On the Home tab, in the Editing group, click the arrow next to Find & Select, and then click Go To Special.
-
Click Conditional formats.
-
Click Same under Data validation.
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.)
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.
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.
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.
-
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.
-
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.
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.
-
Select a rule. Only one rule can be selected at a time.
-
To move the selected rule up in precedence, click Move Up. To move the selected rule down in precedence, click Move Down.
-
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
-
Select the cells that contain the conditional formatting.
-
Click the Quick Analysis Lens 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.
-
-
Click Clear Format.
Find and remove the same conditional formats throughout a worksheet
-
Click on a cell that has the conditional format that you want to remove throughout the worksheet.
-
On the Home tab, click the arrow next to Find & Select, and then click Go To Special.
-
Click Conditional formats.
-
Click Same under Data validation. to select all of the cells that contain the same conditional formatting rules.
-
On the Home tab, click Conditional Formatting > Clear Rules > Clear Rules from Selected Cells.
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.
-
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.
-
Verify or adjust the cells in Apply to range.
-
Choose a Rule Type and adjust the options to meet your needs.
-
When finished, select Done and the rule will be applied to your range.
-
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.
-
The Conditional Formatting task pane displays any rules which apply to specific cells or ranges of cells.
-
Hover over the rule and select Edit by clicking the pencil icon. This opens the task pane for rule editing.
-
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.
-
In an open workbook, select Home > Styles > Conditional Formatting > Manage Rules.
-
The Conditional Formatting task pane opens and displays the rules, scoped to your current selection.
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.
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.
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.
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 one of these formats by their color — just use the context menu.
-
Select the cells that you want to conditionally format using color scales.
-
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.
-
Select the cells that you want to conditionally format.
-
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.
-
Select the cells that you want to conditionally format.
-
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.
-
Select the cells that you want to conditionally format.
-
Select Home > Styles > Conditional Formatting > Highlight Cell Rules.
-
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.
-
Select the cells that you want to conditionally format.
-
Select Home > Styles > Conditional Formatting > Top/Bottom Rules.
-
Select the command you want, such as Top 10 items or Bottom 10 %.
-
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.
-
Select the cells that you want to conditionally format.
-
Select Home> Styles > Conditional Formatting > Top/Bottom Rules.
-
Select the option you want, such as Above Average or Below Average.
-
Enter the values you want to use, and select a format (fill, text, or border color).
-
Select the cells that you want to conditionally format.
-
Select Home > Styles > Conditional Formatting > Highlight Cell Rules > Duplicate Values.
-
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.
-
Click the cell that has the conditional formatting you want to copy.
-
Click Home > Format Painter.
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.
-
Drag the paintbrush across the cells or range of cells you want formatted.
-
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
Checking a Row for a Background Color
Thank you for these great answers!
I especially liked astef’s answer,
Function GetFillColor(Rng As Range) As Long
GetFillColor = Rng.Interior.ColorIndex
End Function
which checks for a cell’s background color by writing the above macro (alt+f11 to open macros), and I used that function to easily create a version of this that checks if a range of three cells in the row have a background color of yellow.
Now this might be performant or not, but it’s a simple way to write the formula. This is the formula in the status column, which will check the other columns selected for any cells with yellow background, using the GetFillColor macro from astef’s answer.
=IF(OR(GetFillColor([@Fees])=6,
GetFillColor([@Interest])=6,
GetFillColor([@Borrowing])=6),
"yellow", "none")
This will return yellow to the cell if there is any yellow background (color index 6), in the cells in the GetFillColor(cell) formulas. Another advantage of writing the GetFillColor() macro is that you can use it to find what color it is you are searching for, by simply selecting an empty cell and writing =GetFillColor(your_cell) where your cell is the cell with the color of which you want the color index number.
To change this to your liking, change the GetFillColor() arguments in the =IF(OR formula above to be the cells in which might be the color, and change the 6 to any color index number you want to find, and change the two «» arguments at the end to any messages you want. The first is printed if the color is found, the second if not. Remember you can use the GetFillColor macro to return the color of any cell you like, in order to know what color index to use in the formulas.
Hope it helps. I’m open to improvement comments.
This tutorial will demonstrate how to highlight cells depending on the answer returned by an IF statement formula using Conditional Formatting in Excel and Google Sheets.
Highlight Cells With Conditional Formatting
A cell can be formatted by conditional formatting based on the value returned by an IF statement on your Excel worksheet.
- First, create the IF statement in Column E.
=IF(D4>C4,”Overdue”,”Ontime”)
- This formula can be copied down to Row 12.
- Now, create a custom formula within the Conditional Formatting rule to set the background color of all the “Overdue” cells to red.
- Select the range you want to apply formatting to.
- In the Ribbon, select Home > Conditional Formatting > New Rule.
- Select Use a formula to determine which cells to format, and enter the formula:
=E4=”OverDue”
- Click on the Format button and select your desired formatting.
- Click OK, and then OK once again to return to the Conditional Formatting Rules Manager.
- Click Apply to apply the formatting to your selected range and then click Close.
The formula entered will return TRUE when the cell contains the word “Overdue” and will therefore format the text in those cells with a background color of red. - To format the “OnTime” cells to green, you can create another rule based on the same range of cells.
- Click Apply to apply to the range.
Highlight Cells If… in Google Sheets
The process to highlight cells that contain an IF Statement in Google Sheets is similar to the process in Excel.
- Highlight the cells you wish to format, and then click on Format > Conditional Formatting.
- The Apply to Range section will already be filled in.
- From the Format Rules section, select Custom Formula and type in the formula.
- Select the fill style for the cells that meet the criteria.
- Click Done to apply the rule.
Содержание
- IF Formula – Set Cell Color w/ Conditional Formatting – Excel & Google Sheets
- Highlight Cells With Conditional Formatting
- Highlight Cells If… in Google Sheets
- Colors in an IF Function
- Excel: Can I create a Conditional Formula based on the Color of a Cell?
- 3 Answers 3
- Checking a Row for a Background Color
- Two ways to change background color in Excel based on cell value
- How to change a cell’s color based on value in Excel dynamically
- How to permanently change a cell’s color based on its current value
- Find and select all cells that meet a certain condition
- Change the background color of selected cells using «Format Cells» dialog
- Change background color for special cells (blanks, with formula errors)
- Use Excel formula to change background color of special cells
- Change the background color of special cells statically
- How to get most of Excel and make challenging tasks easy
IF Formula – Set Cell Color w/ Conditional Formatting – Excel & Google Sheets
This tutorial will demonstrate how to highlight cells depending on the answer returned by an IF statement formula using Conditional Formatting in Excel and Google Sheets.
Highlight Cells With Conditional Formatting
A cell can be formatted by conditional formatting based on the value returned by an IF statement on your Excel worksheet.
- First, create the IF statement in Column E.
=IF(D4>C4,”Overdue”,”Ontime”)
- This formula can be copied down to Row 12.
- Now, create a custom formula within the Conditional Formatting rule to set the background color of all the “Overdue” cells to red.
- Select the range you want to apply formatting to.
- In the Ribbon, select Home > Conditional Formatting > New Rule.
- Select Use a formula to determine which cells to format, and enter the formula:
=E4=”OverDue”
- Click on the Format button and select your desired formatting.
- Click OK, and then OK once again to return to the Conditional Formatting Rules Manager.
- Click Apply to apply the formatting to your selected range and then click Close.
The formula entered will return TRUE when the cell contains the word “Overdue” and will therefore format the text in those cells with a background color of red. - To format the “OnTime” cells to green, you can create another rule based on the same range of cells.
- Click Apply to apply to the range.
Highlight Cells If… in Google Sheets
The process to highlight cells that contain an IF Statement in Google Sheets is similar to the process in Excel.
- Highlight the cells you wish to format, and then click on Format >Conditional Formatting.
- The Apply to Range section will already be filled in.
- From the Format Rules section, select Custom Formula and type in the formula.
- Select the fill style for the cells that meet the criteria.
- Click Done to apply the rule.
Источник
Colors in an IF Function
Written by Allen Wyatt (last updated June 21, 2018)
This tip applies to Excel 2007 and 2010
Steve would like to create an IF statement (using the worksheet function) based on the color of a cell. For example, if A1 has a green fill, he wants to return the word «go», if it has a red fill, he wants to return the word «stop», and if it is any other color return the word «neither». Steve prefers to not use a macro to do this.
Unfortunately, there is no way to acceptably accomplish this task without using macros, in one form or another. The closest non-macro solution is to create a name that determines colors, in this manner:
- Select cell A1.
- Click Insert | Name | Define. Excel displays the Define Name dialog box.
- Use a name such as «mycolor» (without the quote marks).
- In the Refers To box, enter the following, as a single line:
- Click OK.
With this name defined, you can, in any cell, enter the following:
The result is that you will see text based upon the color of the cell in which you place this formula. The drawback to this approach, of course, is that it doesn’t allow you to reference cells other than the one in which the formula is placed.
The solution, then, is to use a user-defined function, which is (by definition) a macro. The macro can check the color with which a cell is filled and then return a value. For instance, the following example returns one of the three words, based on the color in a target cell:
This macro evaluates the RGB values of the colors in a cell, and returns a string based on those values. You could use the function in a cell in this manner:
If you prefer to check index colors instead of RGB colors, then the following variation will work:
Whether you are using the RGB approach or the color index approach, you’ll want to check to make sure that the values used in the macros reflect the actual values used for the colors in the cells you are testing. In other words, Excel allows you to use different shades of green and red, so you’ll want to make sure that the RGB values and color index values used in the macros match those used by the color shades in your cells.
One way you can do this is to use a very simple macro that does nothing but return a color index value:
Now, in your worksheet, you can use the following:
The result is the color index value of cell B5 is displayed. Assuming that cell B5 is formatted using one of the colors you expect (red or green), you can plug the index value back into the earlier macros to get the desired results. You could simply skip that step, however, and rely on the value returned by GetFillColor to put together an IF formula, in this manner:
You’ll want to keep in mind that these functions (whether you look at the RGB color values or the color index values) examine the explicit formatting of a cell. They don’t take into account any implicit formatting, such as that applied through conditional formatting.
For some other good ideas, formulas, and functions on working with colors, refer to this page at Chip Pearson’s website:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10780) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Colors in an IF Function.
Author Bio
With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. Learn more about Allen.
Источник
Excel: Can I create a Conditional Formula based on the Color of a Cell?
I’m a beginner and trying to create a formula that modifies the contents of Cell A1 based on the color of the cell in B2;
If Cell B2 = [the color red] then display FQS.
If Cell B2 = [the color yellow] then display SM.
This is conditional based on the cell fill color.
3 Answers 3
Unfortunately, there is not a direct way to do this with a single formula. However, there is a fairly simple workaround that exists.
On the Excel Ribbon, go to «Formulas» and click on «Name Manager». Select «New» and then enter «CellColor» as the «Name». Jump down to the «Refers to» part and enter the following:
Hit OK then close the «Name Manager» window.
Now, in cell A1 enter the following:
This will return FQS for red and SM for yellow. For any other color the cell will remain blank.
***If the value in A1 doesn’t update, hit ‘F9’ on your keyboard to force Excel to update the calculations at any point (or if the color in B2 ever changes).
Below is a reference for a list of cell fill colors (there are 56 available) if you ever want to expand things: http://www.smixe.com/excel-color-pallette.html
::Edit::
The formula used in Name Manager can be further simplified if it helps your understanding of how it works (the version that I included above is a lot more flexible and is easier to use in checking multiple cell references when copied around as it uses its own cell address as a reference point instead of specifically targeting cell B2).
Either way, if you’d like to simplify things, you can use this formula in Name Manager instead:
In your worksheet, you can use the following: =GetFillColor(B5)
Checking a Row for a Background Color
Thank you for these great answers!
I especially liked astef’s answer,
which checks for a cell’s background color by writing the above macro (alt+f11 to open macros), and I used that function to easily create a version of this that checks if a range of three cells in the row have a background color of yellow.
Now this might be performant or not, but it’s a simple way to write the formula. This is the formula in the status column, which will check the other columns selected for any cells with yellow background, using the GetFillColor macro from astef’s answer.
This will return yellow to the cell if there is any yellow background (color index 6), in the cells in the GetFillColor(cell) formulas. Another advantage of writing the GetFillColor() macro is that you can use it to find what color it is you are searching for, by simply selecting an empty cell and writing =GetFillColor(your_cell) where your cell is the cell with the color of which you want the color index number.
To change this to your liking, change the GetFillColor() arguments in the =IF(OR formula above to be the cells in which might be the color, and change the 6 to any color index number you want to find, and change the two «» arguments at the end to any messages you want. The first is printed if the color is found, the second if not. Remember you can use the GetFillColor macro to return the color of any cell you like, in order to know what color index to use in the formulas.
Hope it helps. I’m open to improvement comments.
Источник
Two ways to change background color in Excel based on cell value
by Svetlana Cheusheva, updated on February 7, 2023
In this article, you will find two quick ways to change the background color of cells based on value in Excel 2016, 2013 and 2010. Also, you will learn how to use Excel formulas to change the color of blank cells or cells with formula errors.
Everyone knows that changing the background color of a single cell or a range of data in Excel is easy as clicking the Fill color button . But what if you want to change the background color of all cells with a certain value? Moreover, what if you want the background color to change automatically along with the cell value’s changes? Further in this article you will find answers to these questions and learn a couple of useful tips that will help you choose the right method for each particular task.
- Change the background color of cells based on value (dynamically) — The background color will change automatically when the cell value changes.
- Change a cell’s color based on its current value (statically) — Once set, the background color will not change no matter how the cell’s value changes.
- Change color of special cells — blanks, with errors, with formulas.
How to change a cell’s color based on value in Excel dynamically
The background color will change dependent on the cell’s value.
Task: You have a table or range of data, and you want to change the background color of cells based on cell values. Also, you want the color to change dynamically reflecting the data changes.
Solution: You need to use Excel conditional formatting to highlight the values greater than X, less than Y or between X and Y.
Suppose you have a list of gasoline prices in different states and you want the prices greater than USD 3.7 to be of the color red and equal to or less than USD 3.45 to be of the color green.
Note: The screenshots for this example were captured in Excel 2010, however the buttons, dialogs and settings are the same or nearly the same in Excel 2016 and Excel 2013.
Okay, here is what you do step-by-step:
- Select the table or range where you want to change the background color of cells. In this example, we’ve selected $B$2:$H$10 (the column names and the first column listing the state names are excluded from the selection).
- Navigate to the Home tab, Styles group, and choose Conditional Formatting >New Rule….
Then click the Format… button to choose what background color to apply when the above condition is met.
In the Format Cells dialog box, switch to the Fill tab and select the color of your choice, the reddish color in our case, and click OK.
Now you are back to the New Formatting Rule window and the preview of your format changes is displayed in the Preview box. If everything is Okay, click the OK button.
The result of your formatting will look similar to this:
Since we need to apply one more condition, i.e. change the background of cells with values equal to or less than 3.45 to the green color, click the New Rule button again and repeat steps 3 — 6 setting the required condition. Here is the Preview of our second conditional formatting rule:
When you are done, click the OK button. What you have now is a nicely formatted table that lets you see the highest and lowest gas prices across different states at a glance. Lucky they are in Texas 🙂
Tip: You can use the same method to change the font color based on the cell’s value. To do this, simply switch to the Font tab in the Format Cells dialog box that we discussed in step 5 and choose your preferred font color.
How to permanently change a cell’s color based on its current value
Once set, the background color will not change no matter how the cell’s contents might change in the future.
Task: You want to color a cell based on its current value and wish the background color to remain the same even when the cell value’s changes.
Solution: Find all cells with a certain value or values using Excel’s Find All function or Select Special Cells add-in, and then change the format of found cells using the Format Cells feature.
This is one of those rare tasks that are not covered in Excel help files, forums and blogs and for which there is no straightforward solution. And this is understandable, because this task is not typical. And still, if you need to change the background color of cells statically i.e. once and forever unless you change it manually again, proceed with the following steps.
Find and select all cells that meet a certain condition
There may be several possible scenarios depending on what kind of values you are looking for.
If you need to color cells with a particular value, e.g. 50, 100 or 3.4, go to the Home tab, Editing group, and click Find Select > Find….
Find…» title=»Go to the Home tab, Editing group, and click Find Select > Find…»>
Enter the needed values and click the Find All button.
Tip: Click the Options button in the right-hand part of the Find and Replace dialog to get a number of advanced search options, such as «Match Case» and «Match entire cell content«. You can use wildcard characters, such as an asterisk (*) to find any string of characters or a question mark (?) to find any single character.
In our previous example, if we needed to find all gas prices between 3.7 and 3.799, we would specify the following search criteria:
Now select any of the found items in the lower part of the Find and Replace dialog window by clicking on it and then press Ctrl + A to select all found entries. After that click the Close button.
This is how you select all cells with a certain value(s) using the Find All function in Excel.
However, what we actually need is to find all gas prices higher than 3.7 and regrettably Excel’s Find and Replace dialog does not allow for such things.
Luckily, there is another tool that can handle such complex conditions. The Select Special Cells add-in lets you find all values in a specified range, e.g. between -1 and 45, get the maximum / minimum value in a column, row or range, find cells by font color, fill color and much more.
You click the Select by Value button on the ribbon and then specify your search criteria on the add-in’s pane, in our example we are looking for values greater than 3.7. Click the Select button and in a second you will have a result like this:
If you are interested to try the Select Special Cells add-in, you can download an evaluation version here.
Change the background color of selected cells using «Format Cells» dialog
Now that all cells with a specified value or values are selected (either by using Excel’s Find and Replace or Select Special Cells add-in) what is left for you to do is force the background color of selected cells to change when a value changes.
Open the Format Cells dialog by pressing Ctrl + 1 (you can also right click any of selected cells and choose «Format Cells…» from the pop-up menu, or go to Home tab > Cells group > Format > Format Cells…) and make all format changes you want. We will choose to change the background color in orange this time, just for a change 🙂
If you want to alter the background color only without any other format changes, then you can simply click the Fill color button and choose the color to your liking.
Here is the result of our format changes in Excel:
Unlike the previous technique with conditional formatting, the background color set in this way will never change again without your notice, no matter how the values change.
Change background color for special cells (blanks, with formula errors)
Like in the previous example, you can change the background color of special cells in two ways, dynamically and statically.
Use Excel formula to change background color of special cells
A cell’s color will change automatically based on the cell’s value.
This method provides a solution that you will most likely need in 99% of cases, i.e. the background color of cells will change according to the conditions you set.
We are going to use the gas prices table again as an example, but this time a couple of more states are included and some cells are empty. See how you can detect those blank cells and change their background color.
- On the Home tab, in the Styles group, click Conditional Formatting >New Rule… (see step 2 of How to dynamically change a cell color based on value for step-by-step guidance).
- In the «New Formatting Rule» dialog, select the option «Use a formula to determine which cells to format«. Then enter one of the following formulas in the «Format values where this formula is true» field:
- =IsBlank()— to change the background color of blank cells.
- =IsError() — to change the background color of cells with formulas that return errors.
Since we are interested in changing the color of empty cells, enter the formula =IsBlank(), then place the cursor between parentheses and click the Collapse Dialog button in the right-hand part of the window to select a range of cells, or you can type the range manually, e.g. =IsBlank(B2:H12) .
Click the Format… button and choose the needed background color on the Fill tab (for detailed instructions, see step 5 of «How to dynamically change a cell color based on value») and then click OK.
The preview of your conditional formatting rule will look similar to this:
If you are happy with the color, click the OK button and you’ll see the changes immediately applied to your table.
Change the background color of special cells statically
Once changed, the background color will remain the same, regardless of the cell values’ changes.
If you want to change the color of blank cells or cells with formula errors permanently, follow this way.
- Select your table or a range and press F5 to open the «Go To» dialog, and then click the «Special…» button.
In the «Go to Special» dialog box, check the Blanks radio button to select all empty cells.
If you want to highlight cells containing formulas with errors, choose Formulas >Errors. As you can see in the screenshot above, a handful of other options are available to you.
Just remember that formatting changes made in this way will persist even if your blank cells get filled with data or formula errors are corrected. Of course, it’s hard to imagine off the top of the head why someone may want to have it this way, may be just for historical purposes 🙂
How to get most of Excel and make challenging tasks easy
As an active user of Microsoft Excel, you know that it has plenty of features. Some of them we know and love, others are a complete mystery for an average user and various blogs, including this one, are trying to shed at least some light on them. But! There are a few very common tasks that all of us have to perform daily and Excel simply does not provide any features or tools to automate them or make an inch easier.
For example, if you need to check 2 worksheets for duplicates or merge rows from single or different spreadsheets, it would take a bunch of arcane formulas or macros and still there is no guarantee you would get the accurate results.
That was the reason why a team of our best Excel developers designed and created 70+ add-ins that we call the Ultimate Suite for Excel. These smart tools handle the most grueling, painstaking and error-prone tasks in Excel and ensure quickly, neatly and flawless results. Below is a short list of just some of the tasks the add-ins can help you with:
Just try these add-ins and you will see that your Excel productivity will increase up to 50%, at the very least!
That’s all for now. In my next article we will continue to explore this topic further and you will see how you can quickly change the background color of a row based on a cell value. Hope to see you on our blog next week!
Источник
В этом руководстве будет показано, как выделять ячейки в зависимости от ответа, возвращаемого формулой оператора IF, с использованием условного форматирования в Excel и Google Таблицах.
Ячейку можно отформатировать с помощью условного форматирования на основе значения, возвращаемого оператором IF на листе Excel.
- Во-первых, мы можем сначала создать оператор IF в столбце E.
= ЕСЛИ (D4> C4, «Просрочено», «Своевременно»)
- Эту формулу можно скопировать до строки 12.
- Теперь мы можем создать собственную формулу в правиле условного форматирования, чтобы установить красный цвет фона всех ячеек «Просрочено».
- Выберите диапазон для применения форматирования (например, E3: E12).
- На ленте выберите На главную> Условное форматирование> Новое правило.
- Выбирать «Используйте формулу, чтобы определить, какие ячейки нужно форматировать“И введите следующую формулу:
= E4 = «Просрочено»
- Нажать на Формат и выберите желаемое форматирование.
- Нажмите Ok, а потом Ok еще раз вернуться к Диспетчер правил условного форматирования.
- Нажмите Подать заявление чтобы применить форматирование к выбранному диапазону, а затем нажмите Закрывать.
Введенная формула вернет ИСТИНА, если ячейка содержит слово «Просрочено», и, следовательно, отформатирует текст в этих ячейках с красным цветом фона.
- Чтобы отформатировать ячейки «OnTime» в зеленый цвет, вы можете создать другое правило на основе того же диапазона ячеек.
- Нажмите Подать заявление применить к ассортименту.
Выделите ячейки, если в Google Таблицах
Процесс выделения ячеек, содержащих оператор IF, в таблицах Google аналогичен процессу в Excel.
- Выделите ячейки, которые хотите отформатировать, а затем нажмите Формат, Условное форматирование.
- В Применить к диапазону раздел уже будет заполнен.
- От Правила форматирования раздел, выберите Пользовательская формула и введите формулу.
- Выберите стиль заливки для ячеек, соответствующих критериям.
- Нажмите Выполнено применить правило.
Размещено в Без рубрики