Chapter 22
Using Data Visualizations and Conditional Formatting

Many people feel their eyes glaze over when they encounter a screen full of numbers. Fortunately, Microsoft offers data-visualization features to Excel that make those screens full of numbers easier to interpret.

The following are some of the possibilities in data visualization:

  • Adding data bars (that is, tiny, in-cell bar charts) to cells based on the cell value. In Excel 2019, data bars can be negative, include an axis, and have new scaling options.

  • Adding color scales to cells based on the cell value. This is often called a heat map. Whereas the old conditional formatting would allow you to apply one color if a value exceeds a certain amount, a color scale applies a range from a gradient based on how high the value is.

  • Adding icon sets (think traffic lights) to cells based on the cell value.

  • Adding color, bold, italic, strikethrough, number formatting, and so on to cells based on the cell values.

  • Quickly identifying cells that are above average.

  • Quickly identifying the top n or bottom n% of cells.

  • Quickly identifying duplicate values.

  • Quickly identifying dates that are today or yesterday or last week.

  • Sorting by color or by icon (after you’ve added icons or color).

Although it is easy to set up basic conditional formatting, you need to know a few tricks, which you discover later in this chapter, for creating better conditional formatting than most people will figure out on their own.

Using Data Bars to Create In-Cell Bar Charts

A data bar is a swath of color that starts at the side of a cell and extends into the cell based on the value of the cell. Small numbers get less color. The largest numbers might be 100% filled with color. This creates a visual effect that enables you to visually pick out the larger and smaller values. Figure 22.1 shows many examples of data bars.

This figure shows eight varieties of data bars. A data bar appears as a single point bar chart in one cell. When you apply a data bar to several items in a column, the collection of cells gives the appearance of a bar chart.
Figure 22.1 Examples of many of the properties in Excel 2019 data bars.

Many options are available in Excel 2019 data bars:

  • Data bars can be solid or a gradient.

  • Values of zero get no data bar, as shown in cell E10.

  • Data bars can be negative. Negative bars are shown in a different color and usually extend to the left of a central axis. You have three choices in where to place the zero axis. In cells B14:B20, the setting is Automatic. Because the largest positive number is further from zero than the smallest negative number, the axis appears slightly to the left of center. This allows the bar for 4.5% in B15 to appear larger than the bar for –3.3% in B17. You can also force the axis to appear in the center, as in cells C14:C20. Or, in a bizarre setting, you can force the negative bars to extend in the same direction as the positive values, but with a different color. There are two philosophical ways to show the negative bars. You can assign –3.3% the most color because it is farthest from zero, or you could assign –1.3% the most color because it is the mathematically the largest of the negative numbers (–1.3% > –3.3%). Excel 2019 uses the latter method.

  • To “reverse” a data bar—to show the most color for the largest number—multiply the numbers by –1 to make them negative. Use a custom number format of “0;0;0;” to display the negative numbers as positive. Make the negative bars extend in the same direction as positive. You end up with the surprising results shown in G1:G11.

  • You can control the color of the positive bar, the positive bar border, the negative bar, the negative bar border, and the axis color.

  • Bars can now extend right to left, as shown in cells C3:C10. This allows comparative histograms as in C2:E10.

  • You can specify the scale of the data bars. Although the scale is initially set to automatic, you can specify that the min or max is set to a certain number or to the lowest value, a percentage, a percentile, or a formula.

  • You can choose to show only the data bar and to hide the number in the cell. This is how I managed to get words in cells E14:E20. The numbers are hidden by the conditional formatting dialog box, and then a linked picture of the words is pasted over the cells. Because the data bars are on a drawing layer above the regular drawing layer, this works.

  • All data bars in a group have the same scale. This is unlike sparklines, where the scale is allowed to change from graphic to graphic.

    Note

    If you don’t like the six basic colors Excel offers for data bars, you can choose any other color, as described in the next section.

Creating Data Bars

Creating data bars requires just a few clicks. Follow these steps:

Caution

In step 1, if you attempt to select a range that contains both units sold and revenue dollars, the size of the revenue numbers overpowers the units sold numbers, and no color appears in the units sold cells.

  1. Select a range of numeric data. Do not include the total in this selection. If the data is in noncontiguous ranges, hold down the Ctrl key while selecting additional areas. This range should be composed of numbers of similar scale. For example, you can select a column of sales data or a column of profit data.

  2. From the Home tab, select Conditional Formatting, Data Bars. You see six built-in colors for the data bars: blue, green, red, orange, bright blue, and pink. The colors appear in both solid and gradient forms. Select one of them. The result is a swath of color in each cell in the selection, as shown in Figure 22.2.

    This figure shows a list of 50 U.S. states and a number representing their agriculture exports. A data bar appears from the left edge of each cell containing a number. The largest exporters have the largest bar.
    Figure 22.2 After applying a data bar, you can easily see that California is a leading exporter of agriculture products.

Customizing Data Bars

By default, Excel assigns the largest data bar to the cell with the largest value and the smallest data bar to the cell with the smallest value. You can customize this behavior by following these steps:

  1. From the Conditional Formatting drop-down list on the Home tab, select Manage Rules.

  2. From the Show Formatting Rules drop-down list, select This Worksheet. You now see a list of all rules applied to the sheet.

  3. Click the Data Bar rule.

  4. Click the Edit Rule button. Alternatively, you could double-click the rule in step 3. You see the Edit Formatting Rule dialog box, as shown in Figure 22.3.

    This figure shows the Edit Formatting Rule dialog box for a data bar. Options include: Show Bar Only, limits for Minimum and Maximum, Solid, or Gradient Fill, Color, the type of border and color, and Bar Direction. A button leads to more options for Negative Values and Axis.
    Figure 22.3 You customize data bars by using the Edit Formatting Rule dialog box.

A number of customizations are available in this dialog box:

  • Select the Show Bar Only setting to hide the numbers in the cells and to show only the data bar.

  • For the Minimum and Maximum values, you can choose from Automatic, Number, Percent, Percentile, Formula, and Smallest/Largest Number. If you select Automatic, Excel chooses a minimum and maximum value. You can override this by setting one value to a specific number.

  • In the Bar Appearance section, you can specify gradient or solid fill for the bar. You can specify a solid border or no border. Two color chooser drop-down lists enable you to change the color of the bar and the border.

  • The Bar Direction drop-down list enables you to select Context, Left to Right, or Right to Left. The default choice of Context is always left to right, unless you are in an international edition of Excel in which the language reading order is right to left.

When you choose Negative Values and Axis, you have new settings to adjust the color of the bar and the border for negative bars. You can also control whether the zero axis is shown at the cell midpoint or at an automatic location based on the relative size of the negative and positive numbers. If the axis is shown, you can adjust the color as well.

Showing Data Bars for a Subset of Cells

In the data bars examples given in the previous sections, every cell in the range receives a data bar. But what if you just want some of the values (for example, the top 20% or the top 10) to have data bars? The process for making this happen isn’t intuitive, but it is possible. You apply the data bar to the entire range. Then you add a new conditional format (a very plain format) to all the cells that you don’t want to have data bars. For example, you might tell Excel to use a white background on all cells with values outside of the top 10.

The final important step is to manage the rules and tell Excel to stop processing more rules if the white background rule is met. This requires clever thinking. If you want to apply data bars to cells in the top 10, you first tell Excel to make all the cells in the bottom 21 look like every other cell in Excel. Turning on Stop If True (in the Conditional Formatting Rules Manager dialog box) is the key to getting Excel to not apply the data bar to cells with values outside of the top 10.

Figure 22.4 shows data bars applied to only the top 10 states.

In this figure, data bars only appear on the top 10 of 31 states shown for soybean exports. The Conditional Formatting Rules Manager reveals the trick: A conditional formatting rule for the Bottom 21 states is set to No Format Set and the Stop If True box is checked for the Bottom 21 rule. Thus, the icon set is run only when the cell contains a top 10 value.
Figure 22.4 Using Stop If True after formatting the lower 21 with no special formatting allows the data bars to appear only for the top states.

Using Color Scales to Highlight Extremes

Color scales are similar to data bars. Instead of having a variable-size bar in each cell, however, color scales use gradients of two or three different colors to communicate the relative size of each cell. Here’s how you apply color scales:

  1. Select a range that contains numbers. Be sure not to include headings or total cells in the selection.

  2. Select Conditional Formatting, Color Scales from the Home tab.

  3. From the Color Scales fly-out menu, select one of the 12 styles to apply the color scale to the range. (Note that this fly-out menu offers subtle differences that you should pay attention to. The first six options are scales that use three colors. These are great onscreen or with color printers. The last six options are scales that use two colors. These are better with monochrome printers.)

In a two-color red/white color scale, the largest number is formatted with a dark red fill. The smallest number has a white fill. All the numbers in between receive a lighter or darker shade of pink based on their position within the range (see Figure 22.5).

A report shows 12 rows of months and six columns of employees. A number shows their open receivables for each month. A Color Scale with higher numbers in a darker fill indicates that Carole and John’s receivables have been steadily increasing.
Figure 22.5 Excel provides a range of shading, depending on the value. You can see that Carole’s and John’s receivables have been increasing throughout the year.

You are not limited to the color scales shown in the fly-out menu. If you select Home, Conditional Formatting, Manage Rules, Edit Rule, you can choose any two or three colors for the color scale.

You also can choose where to assign the smallest, largest, and midpoint values (see Figure 22.6). Column E and the Edit Formatting Rule show how to highlight central values. Using a three-color scale, the minimum and maximum are set to white, whereas the middle numbers are assigned a color.

This figure contrasts three types of color scales. In column A, higher numbers are darker. In column C, smaller numbers are darker. In column E, high and low numbers are light, but numbers around the center are darker. Column E uses a three-color scale with the Midpoint in red and Minimum and Maximum in white.
Figure 22.6 You can choose any colors to use in the color scale.

You should be aware of one strange situation: Normally, Excel lets you mix conditional formatting in the same range. You might apply both a color scale and an icon set.

If you have a three-color scale applied to some cells and choose a different three-color scale from the fly-out menu, the latter choice overwrites the first choice.

However, Excel treats two-color scales as a different visualization than three-color scales. If you have a three-color scale applied and you then try to switch it to a two-color scale using the fly-out menu, Excel creates two rules for those cells. The latter two-color scale is the only one to appear in Excel 2019, but you might be confused when you go to the Manage Rules dialog box to see two different rules applied to the cells.

Using Icon Sets to Segregate Data

Icon sets, which were popular with expensive management reporting software in the late 1990s, have now been added to Excel. An icon set might include green, yellow, and red traffic lights or another set of icons to show positive, neutral, and negative meanings. With icon sets, Excel automatically applies an icon to a cell, based on the relative size of the value in the cell compared to other values in the range.

Excel 2019 ships with 20 icon sets that contain three, four, or five different icons. The icons are always left-aligned in the cell. Excel applies rules to add an icon to every cell in the range:

  • Three-icon sets—For the three-icon sets, you have a choice between arrows, flags, two varieties of traffic lights, signs, stars, triangles, and two varieties of what Excel calls 3 Symbols. This last group consists of a green check mark for the good cells, a yellow exclamation point for the middle cells, and a red X for the bad cells. You can get the symbols either in a circle—that is, 3 Symbols (Circled)—or alone on a white background (that is, 3 Symbols). One version of the arrows is available in gray. All the other icon sets use red, yellow, and green.

  • Four-icon sets—For the four-icon sets, there are two varieties of arrows: a black-to-red circle set, a set of cell phone power bars, and a set of four traffic lights. In the traffic light option, a black light indicates an option that is even worse than the red light. The power bars icons seem to work well on both color displays and monochromatic printouts.

    Tip

    After creating several reports with icon sets, I have started to favor the cell phone power bars, which look good in both color and black and white.

  • Five-icon sets—For the five-icon sets, there are two varieties of arrows, boxes, a five-power bar set, and an interesting set called 5 Quarters. This last set is a monochromatic circle that is completely empty for the lowest values, 25% filled, 50% filled, 75% filled, and completely filled for the highest values.

Setting Up an Icon Set

Icon sets require a bit more thought than the other data visualization offerings. Before you use icon sets, you should consider whether they will be printed in monochrome or displayed in color. Several of the 20 icon sets rely on color for differentiation and look horrible in a black-and-white report.

To set up an icon set, follow these steps:

  1. Select a range of numeric data of a similar scale. Do not include the headers or total rows in this selection.

  2. From the Home tab, select Conditional Formatting, Icon Sets. Select one of the 20 icon sets. Figure 22.7 shows the five-power bar set selected.

    This worksheet shows eight cities and four measurements with an icon set applied. The icon chosen in this case represents cell phone power bar icons with 0, 1, 2, 3, or 4 bars lit. The larger the number, the more bars will be lit in that cell’s icon.
    Figure 22.7 You can choose from the 20 icon sets.

Moving Numbers Closer to Icons

In the top rows of Figure 22.8, the icon set has been applied to a rectangular range of data. The icons are always left aligned. Numbers are typically right-aligned. This can be problematic. Someone might think that the icon at the left side of cell G3 is really referring to the right-aligned number in F3, for example.

This figure shows five ways to align the icon. The default is icon on the left and number on the right. This is confusing because the number on the right side of E2 looks like it should belong to the icon on the left side of F2. One alternative is to use Show Icon Only and center the icon. Another choice is to right-align the numbers but then use the Increase Indent icon to move the number closer to the icon.
Figure 22.8 Changing the alignment of the numbers moves them closer to the icon.

You might try centering the numbers to get the numbers closer to the icons in rows 7–9 in Figure 22.8. This drives purists crazy because the final digit of the 100 in cell H8 doesn’t line up with the final digits of cells H7 and H9.

A better solution is shown in rows 12–14. Keep the numbers right aligned, and use the Increase Indent icon to move the numbers closer to the icon.

If you don’t want to show numbers at all, you can edit the conditional formatting rule and select Show Icon Only. Rows 17–19 show this solution. Ironically, when the numbers are no longer displayed, you can position the icons by using the Left Align, Center Align, and Right Align icons.

The over-the-top solution in rows 22–24 involves using Show Icon Only and then pasting a linked picture of the numbers from other cells.

Here are the steps to create rows 22 through 24:

  1. Select one of the cells with the icon set formatting.

  2. From the Home tab, select Conditional Formatting, Manage Rules.

  3. In the Conditional Formatting Rules Manager dialog box, click the Icon Set rule and then click Edit Rule.

  4. In the middle of the Edit Formatting Rule dialog box, select Show Icon Only. Click OK twice to close the two dialog boxes.

  5. Select all the cells that contain icons and click the Align Center button on the Home tab.

  6. Page down so that you are outside of the printed range. Stay in the same column. Set up a formula to point to the number in the top-left corner of the icon set range. Copy this formula down and over to be the same size as your icon set range. This gives you a range of just the numbers.

  7. Format this range of numbers to be right-aligned with an indent of 1.

  8. Copy this range of numbers.

  9. Go back to the original set of icons and select Paste, Picture Link. A picture of the original numbers appears behind the icons.

Mixing Icons or Hiding Icons

As of Excel 2010, it became possible to mix icons from different sets. In Figure 22.9, A2:C7 is a five-icon set with a mix of icons—gold star, green flag, yellow caution sign, and so on. You start with any five-icon set. Edit the rule and change the icon for each position.

This figure shows two different ways to mix icons from different icon sets. The first example is difficult to read because it mixes a red circle, a yellow triangle, and a gold star. The second example uses the gold star for the highest category and the No Cell icon for the other two categories.
Figure 22.9 Mix icons to create unusual sets.

In A11:D17, scores of 95 and higher receive a gold star, and all other scores get no icon. The open dialog box shows how this is done; the lower two rules show No Cell Icon.

Using the Top/Bottom Rules

The top/bottom rules are a mix of the old- and new-style conditional formatting. They are similar to the old conditional formatting because you must select one formatting scheme to apply to all the cells that meet the rule. However, they are new because rather than specifying a particular number limit, you can ask for any of these conditions:

  • Top 10 Items—You can ask for the top 10, top 20, or any number of items.

  • Top 10%—If 20% of your records account for 80% of your revenue, you can highlight the top 20% or any other percentage.

  • Bottom 10 Items—To highlight the lowest-performing records, select Bottom 10.

  • Bottom 10%—To highlight the records in the lowest 5%, select Bottom 10%.

  • Above Average—You can highlight the records that are above the average. As with all the other rules, the average is recalculated as the numbers in the range change.

  • Below Average—You can highlight the records that are below the average.

To set up any of these conditional formatting rules, follow these steps:

  1. From the Home tab, select Conditional Formatting, Top/Bottom Rules, and then choose one of the six rule types shown in Figure 22.10.

    This figure shows the flyout menu from Home, Conditional Formatting, and Top/Bottom Rules. Choices include Top 10 Items, Top 10%, Bottom 10 Items, Bottom 10%, Above Average, and Below Average.
    Figure 22.10 You can choose one of these six rule types.
  2. The dialog box for above/below average does not require you to select a threshold value, but for the other four rule types, Excel asks you to enter the value for N. As you change the spin button, the Live Preview feature keeps updating the selection with the appropriate number of highlighted cells.

  3. The drop-down list portion of the dialog box initially shows Light Red Fill with Dark Red Text. When you select the drop-down list, you have six default styles and the powerful Custom Format option. If one of the six styles is suitable, choose it. Otherwise, proceed to step 4.

  4. If you choose Custom Format, you are taken to a special version of the Format Cells dialog box. This version has Number, Font, Border, and Fill tabs. You can choose settings on one or more of these tabs. Click OK to close the Format Cells dialog box.

  5. Click OK to close the dialog box for your particular rule.

Excel adds the rule to the list of rules. By default, rules added most recently are applied first.

Using the Highlight Cells Rules

The traditional conditional formatting rules appear in the Highlight Cells Rules menu item of the Conditional Formatting drop-down list, along with several new rules. The traditional rules include Greater Than, Less Than, Between, and Equal To. Note that slightly obscure rules such as Greater Than or Equal To are hidden behind the More Rules option. The following are the traditional rules:

  • Text That Contains—This rule enables you to highlight cells that contain certain text.

  • A Date Occurring—With this rule, you can define conceptual rules such as yesterday, today, tomorrow, last week, this week, next week, last month, this month, next month, or in the last seven days.

  • Duplicate Values—With this rule, you can highlight both records of a duplicate or highlight all the records that are not duplicated.

    Troubleshooting

    Excel’s definition of unique values does not match what you likely mean by unique values.

    To the Excel team, a unique value is a value that occurs exactly once in the range. It does not seem helpful in most situations. Would Amazon care about the products that sold exactly one time? Outside of someone trying to find one-hit wonders from the Billboard music charts, I am not sure when finding values that occur exactly once is useful.

    Instead, I would prefer that Excel highlight the cells that would be left after using Remove Duplicates. Highlight the first occurrence of each product whether it occurs once or 100 times.

    To highlight the first occurrence of a value in C2:C100, use a formula-based condition where =COUNTIF(C$1:C2,C2)=1. Be cautious to use only one dollar sign in that formula. This formula creates an expanding range that looks from C1 down to the current row.

    To create a formula-based conditional format, use Home, Conditional Formatting, New Rule, Use A Formula To Determine Which Cells To Format.

The options for Highlight Cells Rules are shown in Figure 22.11.

This figure shows the flyout menu for Home, Conditional Formatting, and Highlight Cells Rules. Choices include Greater Than, Less Than, Between, Equal To, Text That Contains, A Date Occurring, and Duplicate Values.
Figure 22.11 Many powerful and easy conditions are available in the Highlight Cells Rules menu.

Highlighting Cells by Using Greater Than and Similar Rules

You might think that Greater Than and the similar rules for Less Than, Equal To, and Not Equal To are some of the less powerful conditional formatting rules. In fact, these are the first rules described in this chapter that you can use to base the conditional format threshold on a particular cell or cells. This enables you to build some fairly complex rules without having to resort to the formula option of conditional formatting.

To set up a rule to highlight values greater than a threshold, follow these steps:

  1. Select a range of data. Unlike with the other rules, you might choose to include totals in this selection.

  2. Select Home, Styles, Conditional Formatting, Highlight Cell Rules, Greater Than to display the Greater Than dialog box.

  3. Enter a threshold value in the Greater Than dialog box.

  4. Choose one of the six formats from the With drop-down list. Or choose Custom Format from the With drop-down list to have complete control over the number format, font, borders, and fill.

  5. Click OK to apply the format.

By way of example, let’s look at several options for filling in the threshold value in the Greater Than dialog box. Figure 22.12 shows the conditional formatting rule for all cells greater than 200,000. This is a simple threshold value.

This simple Greater Than dialog box allows you to choose the limit. In this figure, 200,000 is shown and the dialog box specifies a custom format. In the grid behind the dialog box, any number over 200,000 is formatted with red fill and white font.
Figure 22.12 You can format all cells greater than a certain value, such as 200,000.

You can specify a cell as the threshold value. You can either use the reference icon at the right side of the box or type an equal sign and the cell reference. In Figure 22.13, the formula highlights any cell that does not exceed the quota in row 1 above the current cell using =D$1.

This figure shows how the conditional formatting can be based on other values. Numbers in D4:I15 represent monthly sales for six sales reps. Row 1 shows the monthly quota for each sales rep. Select D4:D15 and apply Conditional Formatting for Less Than. In the Less Than dialog box, write a formula for the top-left cell in the selection: =D$1.
Figure 22.13 You can format all cells less than a certain cell. Prefix the cell reference with an equal sign.

The formula in Figure 22.13 has to be written for the active cell. Although D4:I15 is the selected range, the name box shows that D4 is the active cell. The formula of =D$1 is compared to the active cell of D4. The threshold cell then becomes the cell in row 1 that is in the same column as each cell in the selection.

The Greater Than concepts discussed here apply equally well to the Less Than, Equal To, and Between rules. If you need to access other rules, such as Less Than or Equal To, you can follow these steps:

  1. Set up the rule by using Less Than.

  2. From the Conditional Formatting icon, select Manage Rules.

  3. Select the Less Than rule and click Edit Rule.

  4. Use the drop-down list shown in Figure 22.14 to select Less Than or Equal To.

    Although the flyout menu offered Less Than, after setting up the Less Than rule, you can choose Home, Conditional Formatting, Manage Rules to access the Edit Formatting Rule dialog box. This dialog box offers more choices, including Less Than Or Equal To.
    Figure 22.14 After using a quick format with Less Than, you can go to the Manage Rules option to access Less Than or Equal To.

Comparing Dates by Using Conditional Formatting

The date feature was added in Excel 2007. If you are familiar with the reporting engine in Quicken or QuickBooks, the list of available dates will seem similar. A nice feature is that Excel understands the dates conceptually. If you define a feature to highlight dates from last week, the rule automatically updates based on the system clock. If you open the workbook a month from now, new dates are formatted, based on the conditional formatting.

Some of the date selections are self-explanatory, such as Yesterday, Today, and Tomorrow. Other items need some explanation:

  • A Week is defined as the seven days from Sunday through Saturday. Choosing This Week highlights all days from Sunday through Saturday, including the current date.

  • In The Last 7 Days includes today and the six days before today.

  • This Month corresponds to all days in this calendar month. Last Month is all days in the previous calendar month. For example, if today is May 1 or May 31, the period Last Month applies to April 1 through April 30.

Figure 22.15 shows the various formatting options, with a system date of June 22, 2018.

This figure demonstrates how conditional formatting handles A Date In Period. “This Week” is considered Sunday through Saturday. “Last 7 Days” includes today and the previous six days. Options for Today, Yesterday, Tomorrow, This Month, Last Month, and Next Month work as you would expect.
Figure 22.15 Note that Last 7 Days includes today and the previous six days.

The date formatting option would be particularly good for highlighting the items in a to-do list that are due, overdue, or about to be due.

Identifying Duplicate or Unique Values by Using Conditional Formatting

Conditional formatting claims that it can mark either duplicate or unique values in a list of values. It seems that Microsoft missed an opportunity to include a different version of unique values than the one that it included. It would be very useful if Microsoft had included an option to mark only the first occurrence of each unique item.

In column A of Figure 22.16, Excel has marked the duplicate values. Both Adam and Bill appear twice in the list, and Excel has marked both occurrences of the values. You might be tempted to sort by color to bring the red cells to the top, but you still have to carefully go through to delete one of each pair.

The author does not like how Excel marks duplicates or unique values, and I am using this screenshot to show the problems. Six names appear: Adam, Bill, Charley, Adam, Bill, and Dan. When you use conditional formatting to highlight duplicates, both cells containing Adam and both cells containing Bill are marked. When you ask for Unique, only Charley and Dan are marked. Column C shows his dream scenario: The first occurrence of Adam, Bill, Charley, and Dan are marked. The dream scenario is in E2:E7. A formula-based formatting rule of =COUNTIF(E$1:E1,E2)=0 is used.
Figure 22.16 Marking duplicates or unique values with the built-in conditional formatting choices requires additional work to decide which of the duplicates to keep to produce a unique list.

In column C of Figure 22.16, Excel has applied a conditional format to the unique values in the list. In Excel parlance, this means that Excel marks the items that appear only once in a list. If you would keep just the marked cells as a list of the unique names in the list, you would effectively miss any name that was duplicated.

In a perfect world, this feature would have the logic to include one of each name in the conditional format. The conditional formatting in column E resorts to using the fairly complex formula of =COUNTIF(E$1:E1,E2)=0 to highlight the unique values.

Images To learn more about using formulas to mark cells, see “Using a Formula for Rules,” p. 570.

Using Conditional Formatting for Text Containing a Value

The Text That Contains formatting rule is designed to search text cells for cells that contain a certain value.

Figure 22.17 contains a column of cells. Each cell in the column contains a complete address, with street, city, state, and ZIP. It would normally be fairly difficult to find all the records for a particular state. However, this is easy to do with conditional formatting. Follow these steps:

  1. Select a range of cells that contains text.

  2. From the Home tab, select Conditional Formatting, Highlight Cell Rules, Text That Contains.

  3. In the Refers To box, enter a comma, a space, and the state you want to find. Note that this test is not case sensitive (for example, searching for “, pa” is the same as searching for “, PA”).

  4. Choose an appropriate color from the drop-down list.

  5. Click OK to apply the format.

    In this screenshot, several addresses are shown with street, city, state, and zip code. Any addresses located in Pennsylvania are highlighted using Text That Contains, “, PA”.
    Figure 22.17 Without having to use a wildcard character, you can use the Text That Contains dialog box to mark cells based on a partial value.

As with the Find dialog box, you can use wildcard characters. You can use an asterisk (*) to indicate any number of characters and a question mark (?) to indicate a single character.

Tweaking Rules with Advanced Formatting

All the formats available from icons on the Conditional Formatting group are referred to as quick formatting. According to legend, the Excel team bought and read a number of Excel books, and if the author spent a page trying to explain a convoluted way to format something using formulas in conditional formatting, then that option became a quick formatting icon.

Every quick formatting item has an option at the bottom called More Rules. When you click this option and get to the New Formatting Rule dialog box, you find options that didn’t make it as quick formatting icons.

The next section of this chapter discusses using the formula option for conditional formatting. Almost anything is possible by using the formula option, but it is harder to use than the quick formatting icons. If Excel offers a built-in, advanced option, you should certainly use it instead of trying to build a formula to do the same thing.

The lists shown in Tables 22.1 and 22.2 are organized to show all the options for specific rule types. The six rule types are in the top of the New Formatting Rule dialog box. Items listed in the right column are advanced options that are available only by clicking More Rules.

Table 22.1 Options for Formatting Cells Based on Content

Option

Advanced Options Available Using More Rules

Cell value between x and y

Cell value not between x and y

Cell value equal to x

Cell value not equal to x

Cell value greater than x

Cell value less than x

Cell value greater than or equal to x

Cell value less than or equal to x

Specific text containing x

Specific text not containing x

 

Specific text beginning with x

 

Specific text ending with x

Dates occurring yesterday

 

Dates occurring today

 

Dates occurring tomorrow

 

Dates occurring in the last 7 days

 

Dates occurring last week

 

Dates occurring next week

 

Dates occurring last month

 

Dates occurring this month

 

Dates occurring next month

 

More Rules

Blanks

 

No Blanks

 

Errors

 

No Errors

Table 22.2 Options for Formatting Values That Are Above or Below Average

Option

Advanced Options Available Using More Rules

Above the average for the selected range

One standard deviation above the average for the selected range

 

Two standard deviations above the average for the selected range

 

Three standard deviations above the average for the selected range

Below the average for the selected range

One standard deviation below the average for the selected range

 

Two standard deviations below the average for the selected range

 

Three standard deviations below the average for the selected range

Using a Formula for Rules

Excel has three dozen quick conditional formatting rules and twice as many advanced conditional formatting rules. What if you need to build a conditional format that is not covered in the quick or advanced rules? As long as you can build a logical formula to describe the condition, you can build your own conditional formatting rule based on a formula.

Some basic tips can help you successfully use formulas in conditional formatting rules. When you understand these rules, you can build just about any rule you can imagine.

Starting in Excel 2007, a formula is allowed to refer to cells on another worksheet. This enables you to compare cells on one worksheet to a worksheet from a previous month or to use a VLOOKUP table on another worksheet.

Getting to the Formula Box

To set up a conditional format based on a rule, follow these steps:

  1. Select a range of cells.

  2. In the Style group of the Home tab, select Conditional Formatting, Add New Rule.

  3. In the New Formatting Rule dialog box, choose the rule type Use a Formula to Determine Which Cells to Format. You now see the New Formatting Rule dialog box.

The following sections give you some tips for building a successful formula.

Working with the Formula Box

Following are the key concepts involved in writing a successful formula:

  • The formula must start with an equal sign.

  • The formula must evaluate to a logical value of TRUE or FALSE. The numeric equivalents of 1 and 0 are also acceptable results.

  • When you use the mouse to select a cell or cells on a worksheet, Excel inserts an absolute reference to the cell. This is rarely what you need for a successful conditional formatting rule. You can immediately press the F4 key three times to toggle away the dollar signs in the formula.

  • You probably have many cells selected before starting the conditional formatting rule. You need to look at the left of the formula bar to see which cell in the selection is the active cell. If you write a relative formula, you should write the formula that will appear in the active cell. Excel applies the formula appropriately to all cells. This is a key point.

  • If the dialog box is in the way of cells you need to select, you can drag the dialog box out of the way by dragging the title bar. If you absolutely need to get the dialog box out of the way, you can use the Collapse Dialog box button at the right side of the formula box. This collapses the dialog box to a tiny area. To return it to full size, you click the Expand Dialog box button at the right side of the collapsed dialog box.

  • The formula box is one of the evil sets of controls that have three possible statuses: Enter, Point, and Edit. Look in the lower-left corner of the Excel screen. The status initially says that you are in Enter mode. This means that Excel is expecting you to type characters such as the equal sign. If, instead, you use the mouse or arrow keys to select a cell, Excel changes to Point mode. In Point mode, the selected cell’s address is added to the formula box.

    Caution

    The annoying thing about the formula box is that you always start in something called Enter mode. When you are in Enter mode, if you use any of the navigation keys (that is, Page Down, Page Up, left arrow, right arrow, down arrow, up arrow), Excel changes to Point mode and starts inserting random cell addresses at inappropriate places in your formula. Press F2 until you see Edit in the lower-left corner of the Excel window. You can now use the left and right arrows to move through the formula.

The following sections describe several useful conditional formatting rules. This list only scratches the surface of the possible rules you can build. It is designed to generate ideas of what you can accomplish by using conditional formatting.

Finding Cells Within Three Days of Today

The quick formatting feature offers to highlight yesterday or today or tomorrow, but what if you need to find any cells within three days of today, either plus or minus? If the active cell is B2, use a formula of =ABS(TODAY()-B2)<4.

Finding Cells Containing Data from the Past 30 Days

The Excel quick formatting option offers to highlight this month or last month. However, highlighting this month or last month can mean a number of vastly different things. Highlighting this month on the second of the month shows a lot of the future and only one day of the past. The same rule on the 29th of the month highlights a lot of the past and only a few days of the future. It would be more predictable to write a rule that shows the past 30 days.

You create this rule similarly to the way you created the Next Three Days rule in the preceding section. You first compare the date in the cell by using TODAY() to make sure the date in the cell is less than today. If the active cell is F4, you use the following formula:

=AND(F4<TODAY(),(TODAY()-F4)<=30)

To generalize this formula for other periods, such as the past 15 days or the past 45 days, you change the 30 to a different number.

Highlighting Data from Specific Days of the Week

The WEEKDAY() function converts a date to a number from 1 through 7. When used without additional arguments, the value of WEEKDAY(date) for a Sunday is 0 and for Saturday is 7.

Suppose the active cell is H4. If you needed to highlight all the Wednesdays, for example, you could check to see whether WEEKDAY(H4)=4. To find all the Fridays, you would check to see whether WEEKDAY(H4)=6. To find either date, you would use =OR(WEEKDAY(H4)=4,WEEKDAY(H4)=6).

To generalize this formula, you could substitute any number from 1 through 7 to highlight Sundays, Mondays, and so on.

Highlighting an Entire Row

Most conditional formatting highlights a cell based on the value in that cell. In this case, you would like to highlight the entire row for the row with the largest product sale.

In Figure 22.18, cell A2 is the active cell. You need to select the entire range of A2:G14. Your goal is to write a rule for all those cells that will always look at column D, but the row will vary based on the cell being evaluated. In this case, and in any case in which you want to highlight the entire row based on one column, you use the mixed reference with a dollar sign before the column letter. You want to see whether =$D2 is equal to the largest value in the range.

In this figure, the entire row is highlighted based on the revenue in column F with the largest value.
Figure 22.18 The combination of a mixed reference and the absolute reference enables you to highlight an entire row.

To find the largest value in column D, you use an absolute reference to D2:D14—that is, =MAX($D$2:$D$14). The conditional formatting formula for this specific case is =$D2=MAX($D$2:$D$14).

To change this rule to highlight the smallest value in column D, you change MAX to MIN. To base the test on another column, change D to the other column in three places in the formula.

Highlighting Every Other Row Without Using a Table

You might find yourself using the Format as Table feature only to add alternating bands of color to a table. If you don’t need the other table features, using a conditional format can achieve the same effect.

Do you remember when you were first learning to do division? You would express the quotient as an integer and then a remainder. For example, 9 divided by 2 is 4 with a remainder of 1, sometimes written as 4R1.

The trick to formatting every other row is to check the remainder of the row number after dividing by 2. Excel has functions that make this easy. First, =ROW() returns the row number of the given cell. Next, =MOD(ROW(),2) divides the row number by 2 and tells you the remainder. The task is then simply to highlight the rows where the remainder is equal to 1 or equal to zero.

Note

The Excel table formatting enables you to create alternate formatting in which every other two rows are formatted. To duplicate this with conditional formatting, you have to divide the row number by 4 and examine the remainder. There are four possible remainders: 0, 1, 2, and 3. You can look for results greater than 1 or less than 2 to be formatted. To do this, you change the preceding formula to =MOD(ROW(),4)<2.

In Figure 22.19, the active cell is A2. The formula to achieve the banding effect is =MOD(ROW(),2)=0.

In this figure, every other row has a red fill. A formula-based Conditional Formatting rule uses =MOD(ROW(),2)=1.
Figure 22.19 It is possible to create a row-banding effect without using the Excel table formatting.

To generalize this formula for your particular data set, you could change A2 to be the active cell’s address.

Combining Rules

Excel allows multiple conditions to evaluate to TRUE. In legacy versions of Excel, when a condition was met, Excel quit evaluating additional conditions. For each rule in Excel 2019, you can decide whether Excel should stop evaluating additional rules or whether Excel can continue evaluating rules.

For example, one rule might set the font color to blue. Another rule might set the font style to bold. Cells meeting both rules can be formatted in blue bold. Cells meeting one rule can be either blue or bold. Cells meeting neither rule will be in normal font style.

If two rules attempt to create conflicting formatting, Excel uses the first rule in the list. For example, if Rule 1 turns the font red and Rule 7 turns the font blue, the font is red.

Ten types of formatting can be changed in each cell. Naturally, each type conflicts with others of the same type. Only the first rule that evaluates to TRUE can change the fill color.

Very few formatting styles conflict with each other. Only the cell fill and the color scale are mutually exclusive. Otherwise, you can have up to nine rules evaluate to TRUE for any given cell. Table 22.3 illustrates the interplay between the ten formatting styles.

Table 22.3 Cell Formatting Styles

Style

Effect

Font color

Changes the font color for cells meeting a condition.

Font style

Applies normal, bold, italic, or bold italic to cells meeting a condition.

Underline

Adds or removes single or double underlining for cells meeting a condition.

Strikethrough

Applies strikethrough for cells meeting a condition.

Number format

Changes the number format for cells meeting a condition.

Border

Alters the borders for cells meeting a condition. You might think that you could combine two rules that both affect the border. For example, you might want to make the top border blue for cells that meet Rule 1 and the right border red for cells that meet Rule 2. Even though this conceptually makes sense, Excel allows only the first true rule to change the borders.

Cell fill

Changes the cell background for cells meeting a condition. Amazingly, this works fine in combination with data bars. (The cell fill appears to the right of the data bar.) It also works fine with icon sets, and it works fine with all the preceding options. However, cell fill and color scales cannot coexist. Only the first true rule appears in the cell.

Color scale

Changes the cell background for all cells in the range, with the color being determined by the value of one cell in relation to the other cells in the range. This rule can coexist with everything but itself and the cell fill formatting.

Data bar

Adds an in-cell bar chart in each cell. This rule can coexist with any other type of rule.

Icon set

Adds an icon in the left side of the cell. This rule can coexist with any other type of rule.

You can use a number of ways to clear conditional formats. A few quick options are available from the ribbon:

  • You can highlight the entire range with conditional formatting and then use Home, Styles, Conditional Formatting, Clear, Selected Cells. This removes all conditions from the current selection.

  • To clear all the conditional formats from the current worksheet, you can use Home, Styles, Conditional Formatting, Clear, Entire Sheet. This is handy if you have only one set of rules set up on the sheet. You can delete all the rules without having to select the entire range.

    Note

    Deleting columns or rows deletes the rules associated with those columns or rows. Selecting Home, Editing, Clear, All or Home, Editing, Clear, Formats removes the rules.

  • If you have rules assigned to a pivot table or a table, you can select one cell in the pivot table or table. This enables new options for Home, Styles, Conditional Formatting, Clear, This Table or Home, Styles, Conditional Formatting, Clear, This PivotTable.

If you have multiple rules assigned to a range and you need to delete just a portion of those rules, you can use Home, Styles, Conditional Formatting, Manage Rules. In the Conditional Formatting Rules Manager dialog box, you should use the top drop-down list to display rules in the current selection, this worksheet, or any other worksheet. You can then highlight a specific rule and click the Delete Rule button.

Extending the Reach of Conditional Formats

In every example in this chapter, you have been advised to highlight the entire range before setting up the conditional format. It is also possible to assign a conditional format to one cell and then extend the rule to other cells. There are three ways to copy a conditional format:

  • You can select a cell with the appropriate rule and then press Ctrl+C to copy it. Then you select the new range and select Home, Clipboard, Paste, Paste Special, Formats, OK to copy the conditional formatting from the one cell to the entire range.

  • Select a cell with the appropriate rule. Click the Format Painter icon in the Home tab. Select a new range to paste the conditional format to the new range.

  • You can select Home, Styles, Conditional Formatting, Manage Rules. Then you select a rule. In the Applies To column, you see the list of cells that have this rule. You can type a new range there or use the collapse button to make the dialog box smaller so that you can highlight the new range.

When you are using conditional formats that compare one cell to the entire range, using the second method is safer to ensure that Excel understands your intention.

Special Considerations for Pivot Tables

This section talks about the special conditional formatting options that are available for pivot tables.

Images See Chapter 15, “Using Pivot Tables to Analyze Data,” to review the detailed discussion of pivot tables.

A typical pivot table might contain two or more levels of summary data. In the pivot table in Figure 22.20, for example, cells H4:J16 contain sales data. However, if you tried to create a data bar for this entire range, the subtotal values in rows 9 and 15 would make the data bars in the other rows look too small.

After applying conditional formatting to a cell in a pivot table, a new on-grid drop-down list appears that looks like a pivot table icon. Open that menu for choices that let you apply the formatting to Selected Cells, All Cells Showing Sum Of Sales, or All Cells Showing Sum Of Sales For Customer and Product.
Figure 22.20 The trick to a successful conditional format in a pivot table is to apply the format only to items at the same detail level.

To set up a data bar for the detail items in a pivot table, follow these steps:

  1. Select a detail cell in the pivot table. In Figure 22.20, a cell such as H4 will do.

  2. Choose any visualization from the Conditional Formatting drop-down list. In Figure 22.20, the 3-stars icons set is shown.

  3. A tiny pivot icon appears to the right of the cell. Click this drop-down list to access three conditional formatting settings for pivot tables. The choices are the following:

    1. Selected Cells—You can apply the rule to just the one cell. This is not what you want in this case.

    2. All Cells Showing Sum Of Sales Values—You can apply the rule to cells including the total column, grand total row, and all the subtotal rows. Remember that the size of the grand total causes all the detail items to have data bars that are too small.

    3. All Cells Showing Sum Of Sales Values for “Customer” and “Product”—This is the option you use most of the time. The meaning of this option is dependent on careful selection of a detail cell in step 1. If you selected a subtotal row instead, this option would apply the data bars only to the subtotal rows.

The actual words in the second and third options vary, depending on the fields displayed in your pivot table. For successful pivot table formatting, select the third option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.56.194