In this chapter
Using Traditional Formatting 893
Other Formatting Techniques 915
Formatting adds interest and readability to documents. If you have taken time to create a spreadsheet, you should also take the time to make sure that it is eye catching and readable.
You can format documents in Excel 2007 with any of these three methods:
You could easily open a blank worksheet and fill it with data without ever touching any of Excel’s formatting commands. The result would be functional but not necessarily readable or eye catching.
Figure 32.1 contains an unformatted report in Excel.
Figure 32.2 contains exactly the same data but with formatting applied. The formatted report is more interesting than the unformatted one. The reader can instantly focus on the totals for each line. Headings are aligned with the data. Borders break the data into sections. Accent colors highlight the subtotals and totals. The title is prominent, in a larger font and headline typeface. Numeric formatting has removed the extra decimal places and added thousands separators. The column widths are adjusted properly. A short row adds a visual break between the product lines. Headings for each product line are rotated, merged, and centered.
The formatting applied to Figure 32.2 takes a few extra minutes, but it dramatically increases the readability of the report. You’ve taken the time to put the worksheet together, and it is worth a couple minutes to help the consumer of the worksheet easily read it.
Formatting is typically carried out in the Format Cells dialog box or using the formatting icons located on the Home ribbon.
In Excel 2007, Microsoft took the icons formerly on the Formatting toolbar and arranged them in the Font, Alignment, and Number groups on the Home ribbon, as shown in Figure 32.3. Additional column- and row-formatting commands are available in the Format drop-down in the Cells group on the Home ribbon.
While analyzing SQM data from Microsoft Excel 2003, the Excel 2007 development team decided to promote some settings from the Format Cells dialog to the Home ribbon. Icons for wrapping text, vertical alignment, and text rotation have therefore been added to the icons formerly on the Formatting toolbar.
If your favorite setting is not on the Home ribbon, you can take one of the four entry paths to the Format Cells dialog, which provides access to additional settings, such as Shrink to Fit, Strikethrough, and more border settings:
As shown in Figure 32.4, the Format Cells dialog includes six tabs:
Do you ever go shopping for hardware at a general-purpose store? I am amazed at their ability to have almost what I need but to never actually have what I need. I usually end up cursing my decision to stop at the general-purpose retailer and drive another mile down the road to Home Depot or Lowe’s, where they always have exactly what I need.
Using the Number group on the Home ribbon is like shopping at a general-purpose retailer. It has a lot of settings for numeric formatting, but most of the time, they are not exactly what you need, and you end up visiting the Number tab on the Format Cells dialog.
To start, there are three icons, for currency, percentage, and comma style. The Percentage icon is useful. Unfortunately, the Currency and Comma icons both apply an Accounting style to a cell, and the Accounting style is inappropriate for everyone except accountants. Furthermore, these three icons are not toggle buttons. When you use one of them, there is not an icon to quickly go back to a general style (other than Undo).
The Increase and Decrease Decimal icons are useful. Each click of one of these buttons forces Excel to show one more or one fewer decimal place. If you have numbers showing two decimal places in all cells, a couple clicks on the Decrease Decimal icon solves the problem.
Figure 32.5 shows the Currency, Percentage, Comma, Increase Decimal, and Decrease Decimal buttons in the Number group of the Home ribbon.
Above the five buttons in the Number group is a new drop-down that has a dozen popular number styles. Figure 32.6 shows the styles in the drop-down. The range A2:F12 shows these styles applied to four different numbers.
Here are some comments and cautions about using the number styles from the drop-down in the Home ribbon:
The Format Cells dialog offers far more number formats than the Home ribbon. My favorite number format can only be accessed through the Format Cells dialog. I find that I avoid the buttons in the Number group in the Home ribbon and go directly to the Format Cells dialog.
You display the Format Cells dialog by clicking the double-diagonal arrow icon in the lower-right corner of the Number group of the Home ribbon. When you open the Format Cells dialog this way, the Number tab is the active tab.
There are 12 categories on the left side of the Number tab. The General and Text categories each have a single setting. The Custom category allows you to use formatting codes to build any number format. The remaining nine categories each offer a collection of controls to customize the numeric format.
Using numeric formatting with thousands separators is my favorite format. The thousands of separators make the number easy to read. You can easily suppress the cents from the numbers. Microsoft does not offer buttons on the Home ribbon to select this format. The comma button would be a perfect place for it, but instead, Microsoft assigns that to the accounting format.
To format cells in numeric format, you follow these steps:
Figure 32.7 shows the Number category of the Format Cells dialog.
There are two categories for currency. The Currency category is identical to the Number category shown in Figure 32.7, with the addition of a currency symbol drop-down. This drop-down offers 390 different currencies from around the world.
The second category, Accounting, always shows negative numbers in parentheses. With this category, the currency symbol is always left-aligned in the cell. The last digit of positive numbers appears one character from the right edge of the cell so that positive and negative numbers line up.
The Date category offers 17 built-in formats for displaying dates. The Time category offers nine built-in formats for displaying time. Each category has two formats that display both date and time.
The date formats vary from short dates, such as 3/14, to long dates, such as Wednesday, March 14, 2001. You should pay particular attention to the Date formats and the Sample box. Some formats show only the month and the day. Other formats show the month and the year. The values in the Type box are for March 14, 2001. Types such as March-01 display month-year. Types such as 14-Mar are displaying day-month.
An interesting format near the bottom of the list is the M type. This displays month names in JFMAMJJASOND style, as shown in Figure 32.8. Readers of the Wall Street Journal’s financial charts will instantly recognize that in this style, each month is represented by the first letter of the month. It works great when used as the labels along the x-axis of a chart.
In the Time category, you should pay attention to an important distinction between the 1:30 PM, 13:30, and 37:30:55 types. The first type displays times from 12:00 AM through 11:59 PM. The second type displays military time. In this system, midnight is 0:00, and 11:59 PM is 23:59. Neither of these types displays hours in excess of 24 hours. If you are working on a weekly timesheet or any application where you need to display hours that total to more than 24 hours, you need to use the 37:30:55 type in the Time category. This format is one of few that displays hours in excess of 24.
The Fractions category rounds a decimal number to the nearest fraction. Types include fractions in halves, quarters, eighths, sixteenths, tenths, and hundredths. In addition, the first three types specify that the decimal should be reduced to the nearest fraction with up to one, two, or three digits in the denominator.
Figure 32.9 shows a variety of decimals formatted with five different fractional types. In Row 14, notice that this random number can appear as 1/2, 49/92, or 473/888 when using the Up To n Digit types. Excel rounds the number to the closest fraction.
In Column E, note that if you ask Excel to show the number in eighths, Excel uses 4/8 and 2/8 instead of 1/2 or 1/4.
I am sure that I spent way too much time in junior high math learning how to reduce fractions. The first three fraction types of number formatting in Excel eliminate the need for manually reducing fractions.
Spreadsheets were invented in Cambridge, Massachusetts. If you enter the zip code for Cambridge (02138) in a cell, Excel does not display the zip code correctly. It truncates the leading zero, giving you a zip code of 2138.
To combat this problem, Excel provides four special formatting types, all of which are U.S. centric:
Figure 32.10 shows cells formatted with the four types, which are available in the Special category.
Note
If you happen to live in one of the other 191 countries in the world besides the United States, you will undoubtedly need other formatting for your postal codes, telephone numbers, or national ID numbers. You can create number formats such as the ones shown in the Special category as well as the other formats you might need by using the Custom category, as discussed in the next section.
Custom number formats provide incredible power and flexibility. Although you don’t need to know the complete set of rules for them, you will probably find a couple custom number formats that work perfectly for you and be able to make use of them.
To use a custom number format, you follow these steps:
A custom number format can contain up to four different formats, each separated by a semicolon. The semicolons divide the format into up to four zones. Excel allows different formatting, depending on whether a cell contains a positive number, negative number, zero, or text. You need to keep in mind the following:
In Figure 32.11, a custom number format uses all four zones. The table in Rows 11:14 shows how various numbers are displayed in this format. (Cell B14 appears in red type.)
You can display a mix of text and numbers in a numeric cell. To do so, you simply include the text in double quotation marks. For example, "The total is "$#,##0
precedes the number with the text shown in quotes.
If you need a single character, you can omit the quotation marks and precede the character with a backslash (). For example, the code
$#,##0,,M
displays numbers in millions and adds an M indicator after the number.
Some characters require neither a backslash nor quotation marks. These special characters are $ - + / ( ) : ! & ' ~ { } = < >
and the space character.
To add a specific amount of space to a format, you enter an underscore followed by a character. Excel then includes enough space to include that particular character. One frequent use for this is to include _)
at the end of a positive number to leave enough space for a closing parenthesis. The positive numbers then line up with the negative numbers shown in parentheses.
To fill the space in a cell with a repeating character, you use an asterisk followed by the character. For example, the format **0
fills the leading space in a cell with asterisks. The format 0*-
fills the trailing space in a cell with hyphens.
If you are expecting numbers but think you might occasionally have text in the cell, you can use the fourth zone of the format. You use the @
character to represent the text in the cell. For example, 0;0;0;"Unexpected entry of "@
highlights the text cells with a note.
You use a zero as a placeholder when you want to force the place to be included. For example, 0.000
formats all numbers with three decimal places. If the number has more than three places, it will be rounded to three decimal places.
You use a pound sign (#
) as a placeholder to display significant digits but not insignificant zeros. For example, 0.###
displays up to three decimal places, if needed, but can display 1.
for a whole number.
You use a question mark to replace insignificant zeros on either size of the decimal point with enough space to represent a digit in a fixed-width font. This format was designed to allow decimal points to line up, but with proportional fonts, it may not always work.
To include a thousands separator, you include a comma to the left of the decimal point. For example, #,##0
displays a thousands separator.
To scale a number by thousands, you include a comma after the numeric portion of the format. Each comma divides the number by a thousand. For example, 0,
displays numbers in thousands, and 0,,
displays numbers in millions.
The condition codes available in numeric formatting predate conditional formatting by a decade. You should consider the flexible conditional formatting features (see Chapter 9, “Visualizing Data in Excel”) for any new conditions, but in case you encounter an old worksheet with these codes, it is valid to use eight colors in the format: red, blue, green, yellow, cyan, black, white and magenta. You include the color in square brackets. It should be the first element of any numeric formatting zone.
You can include a condition in square brackets after the color but before the numeric formatting. For example, [Red][<=100];[Blue][>100]
displays numbers under 100 in red and other numbers in blue. The U.S. telephone special format uses this custom condition [<=9999999]###-####;(###) ###-####
.
Although many of these settings are arcane, I still regularly use many of the date and time formats shown in Table 32.1. The various m
and d
codes allow flexibility in expressing dates.
The custom number format m/d/yy
displays the month and day numbers as one digit if possible. For example, dates formatted with this code would display as 1/9/08, 1/31/08, 9/9/09, and 12/31/08.
A custom number format of mm/dd/yy
always uses two digits to display the month and day. Examples are 01/09/08 and 01/31/08.
The remaining date and time codes can display months as Jan, January, or J and days as 1, 01, Fri, or Friday.
Note
Note that the letter m
can be used as either a month or as a minute. If the m
is preceded by an h
or followed by an s
, Excel assumes that you are referring to minutes. Otherwise, the month is displayed instead.
To display numbers in scientific format, you use E-
, or E+
exponent codes in a zone.
If a format contains a zero (0) or pound sign (#) to the right of an exponent code, Excel displays the number in scientific format and inserts an E
. The number of zeros or pound signs to the right of a code determines the number of digits in the exponent. E-
or e-
places a minus sign by negative exponents. E+
or e+
places a minus sign by negative exponents and a plus sign by positive exponents.
Take the following, for example:
Worksheets look best when the headings above a column are aligned with the data in the column. Excel’s default behavior is to left-align text and to right-align values and dates.
On the left side of Figure 32.12, the month headings in Row 5 are left-aligned, and the numeric values starting in Row 6 are right-aligned. This makes the worksheet look haphazard. To solve the problem, you can right-align the headings cells. The right side of Figure 32.12 shows the headings right-aligned.
To right-align cells, you select the cells and click the Right Align icon in the Alignment group of the Home ribbon.
Note
The Alignment tab of the Format Cells dialog offers additional alignment choices, such as justified, distributed, and indented.
There are three icons in the Font group of the Home ribbon for changing font size:
Note
By using the Font tab of the Format Cells dialog, you can type an intermediate font size, such as 13.
Changing the font typeface is vastly improved in Excel 2007. For a couple versions, the Font drop-down has been able to show the font names in the style of each font. Now, in Excel 2007, as you hover over the font, Live Preview shows you how the font will look in the selected cells in your worksheet, as shown in Figure 32.14. The Font name drop-down is in the Font group of the Home ribbon.
Three icons in the Font group in the Home ribbon allow you to change the font to apply bold, italic, and underline. Unlike the icons in the Number group, these icons behave properly, toggling the property on and off. The Bold icon is a bold letter B. The Italic icon is an italic letter I. The Underline icon is either an underlined U
or a double-underlined D
. The Underline icon is actually a drop-down. As shown in Figure 32.15, you can choose the drop-down to change from Single Underline to Double Underline.
The underline style underlines the characters in the cell. If you have a cell that contains 123, the underline is 3 characters wide. If you have a cell with 1,234,567.89, the underline is 12 characters wide. If you need an underline to extend the entire width of a cell, you can select Single Accounting Underline or Double Accounting Underline on the Font tab of the Format Cells dialog. Or you can use a bottom border in the cell.
Note
By using the Font tab of the Format Cells dialog, you can also apply strikethrough, superscript, and subscript.
There are 1.7 billion unique combinations of borders for any four-cell range. The Borders drop-down in the Font group of the Home ribbon offers 13 of the most popular options, as shown in Figure 32.16.
To apply borders to a range, you follow these steps:
There is an important concept to understand when applying borders to a range. Say that you select 20 rows by 20 columns (for example, cells A1:T20). If you apply a top border by using the drop-down, only the top row of cells A1:T1 have the border. Often, this is not what you were expecting. You might have wanted a border on the top of all 400 cells. In the Format Cells dialog box, there is a representation of a 2×2 cell range, as shown in Figure 32.17. The border style drawn in the top edge of this box affects only the top edge of the range. The border style drawn in the middle horizontal line of the box affects all the horizontal borders on the inside of the selected range.
The fastest way to select all horizontal and vertical borders in the range is to click the Outline button and then the Inside button in the Presets section of the dialog.
Excel 2007 adds the ability to use a gradient to fill a cell. This can provide an interesting look for a title cell. Gradient formatting is available only in the Format Cells dialog.
The Font group on the Home ribbon offers a paint bucket drop-down and an A drop-down. The paint bucket is a color chooser for the background fill of the cell. The A drop-down is a color chooser for the font color in the cell. Both drop-downs offer 6 shades of the 10 theme colors, 10 standard colors, and the option More Colors. The paint bucket drop-down also offers the menu choice No Fill, as shown in Figure 32.18.
The More Colors drop-down offers the two-tabbed Colors dialog. You can either choose a color from the Standard tab or enter an RGB value on the Custom tab.
The two-color gradient in a cell is a new feature in Excel 2007. To activate this feature, you follow these steps:
Figure 32.19 shows the Fill Effects dialog. Cell A1 contains a vertical shading, from left to right. Cell A4 shows the opposite variant of vertical shading. Cell A9 shows the from-the-center variant of the vertical shading. Cell A13 shows a diagonal-down shading style.
You can adjust the width of every column in a worksheet. In many cases, narrowing the columns to reduce wasted space can allow a report to fit on one page.
I always say that there are three or more ways to accomplish most tasks in Excel. In most cases, I have a favorite method to do any task and use that method exclusively. However, setting column widths and row heights is a task where I actively use many different methods, depending on the circumstances.
You can use the following seven methods to adjust column width. Every one of them applies equally well to adjusting row heights:
In general, merged cells are bad. If you have a merged cell in the middle of a data table, you will be unable to sort the data. You will be unable to cut and paste data unless the same cells are merged. However, it is okay to use merged cells as a title to group several columns together.
In Figure 32.22, the Consumer and Professional headings correspond to the columns B:F and G:K, respectively. It would be appropriate to center each heading above its columns.
To merge and center cells, you follow these steps:
Note that after you merge the cells, the entire range becomes one cell. In Figure 32.24, the word Consumer is in an ultra-large Cell B2. In this worksheet, cells C2, D2, E2, and F2 no longer exist.
Note
The Merge Across selection in the drop-down merges the cells but does not center the value in the merged cell across the cells below.
Vertical text is difficult to read. However, there are times when space considerations make it advantageous to use vertical text. In Figure 32.25, for example, the names in Row 5 are much wider than the values in the rest of the table. If you use Format, Autofit Selection, the report is too wide.
In the Alignment tab of the Home group, an Orientation drop-down offers five variations of vertical text. Figure 32.26 compares the five available options. Although the Angle options look great, they only reduce the column width by 12%. Vertical Text reduces the column width by 75% but takes far more vertical space. The option Rotate Text Up reduces the column width by 73% and takes up less than half the vertical space of the Vertical Text option.
Note
After you rotate the text, select the Cells section of the Home ribbon and then select Format, AutoFit Selection again to narrow the columns.
If you need more control over the text orientation, you can select the Alignment option in the drop-down to display the Alignment tab of the Format Cells dialog. This tab allows rotation from 90 degrees to -90 degrees, in 1 degree increments, as shown in Figure 32.27.
Instead of using the settings in the Font group of the Home ribbon, you could format a report by using the built-in cell styles. Cell styles have been popular in Word for over a decade. They have been available in Excel, but because they were not given a spot on the Formatting toolbar, few people took advantage of them.
Figure 32.28 shows the styles available when you select Styles, Cell Styles in the Home ribbon.
An advantage to using cell styles is that you can quickly convert the look and feel of a report by choosing from the themes on the Page Layout ribbon. Figure 32.29 shows 1 of the 20 available themes applied to the report.
The Cell Styles gallery offers a menu item to add additional styles to a workbook. Using cell styles provides an interesting alternative to the traditional method of formatting.
You have the basics for formatting cells and worksheets. The rest of this chapter provides an overview of various formatting tips and tricks. These techniques discuss how to mix formatting within a single cell, wrap text in several cells, and use cell comments.
Occasionally, you might find yourself entering a short memo on a worksheet. This might occur as an introduction or as instructions to a lengthy workbook. Although Excel is not a full-featured word processor, it can do a few word processing tricks.
One trick is to highlight individual characters in a cell in order to add emphasis or to make them stand out. You can do this to any cell that does not contain a formula. In Figure 32.30, for example, text has been typed in Column A and allowed to extend over the edge of the column into Columns A:J. One word in Row 4 is in a bold, underlined, red font.
To format individual characters, you follow these steps:
Caution
Using the technique described later in this chapter, in the section “Justifying Text in a Range,” to justify text in a range wipes out the individual character formatting. Be sure to use that trick before doing a lot of formatting with the tricks described here.
Excel offers a default font setting to be used for all new workbooks. With the Excel 2007 paradigm of themes, the default font for new workbooks is initially the generic value of BODY FONT. This is not an actual font; it instead refers to the main font used by the current theme.
Note
If you like the concept of using themes to change the look and feel of a document, you should leave the default font setting as BODY FONT and change the font used in the theme. (For more information on customizing themes, see Chapter 5, “Galleries, Live Preview, and Themes.”)
To change your default font for all new workbooks, you follow these steps:
The default font setting only has an effect in new workbooks. It does not affect workbooks previously created.
You might have one column in a table that contains long, descriptive text. If the text contains several sentences, it would be impractical to make the column wide enough to include the longest value in the column. Excel offers the capability to wrap text on a cell-by-cell basis to solve this problem.
When you wrap text, one annoying feature of Excel becomes evident. All cells in Excel are initially set to have their cell contents aligned with the bottom of the cell. You probably don’t notice this because most cells in Excel are the same height. When you wrap text, however, the cell heights double or more, and it becomes very evident that the bottom alignment looks strange in this situation. To correct this problem, you follow these steps:
Figure 32.31 shows a table where the descriptions in Column B have had their text wrapped and all the cells are top-aligned.
When using Excel as a word processor to include a paragraph of explanatory body copy in a worksheet, you usually have to decide where to manually break each line.
Excel offers a command that reflows the text in a paragraph in order to fit a certain number of columns.
You need to do some careful preselection work before invoking the command. You follow these steps:
Cell comments can contain a few sentences or paragraphs to explain a cell. Although the default is for all comments to use a yellow sticky-note format, you can customize comments with colors, fonts, or even pictures.
In the default case, a comment causes a red triangle to appear in a cell. If you hover over the triangle, the comment appears. Alternatively, you can request that comments be displayed all the time. This creates an easy way to add instructions to a worksheet.
You follow these steps to insert a comment, format it, and cause it to be displayed continuously:
Figure 32.34 shows a comment that has been formatted, resized, and set to be displayed.
Excel worksheets tend to have many similar sections of data. After you’ve taken the time to format the first section, it would be great to be able to copy the formats from one section to another section. Excel 2007 offers two methods for doing this: pasting formats and using the Format Painter icon.
An option on the Paste Special dialog allows you to paste only the formats from the Clipboard. The rules for copying and pasting formats are as follows:
You follow these steps to copy formats:
The disadvantage of using the Paste Special Formats method is that it does not change column widths. After the formats are copied from B:F to H:L in Figure 32.36, notice that Columns I:K did not pick up the narrower column widths from the source columns. This problem can be solved by using the Format Painter tool, described in the next section.
The Format Painter icon appears in the Clipboard group of the Home ribbon. The prominent location of the icon might encourage you to attempt to use this feature. The Format Painter is still tricky to use.
To copy a format from a source range to a destination range, you follow these steps:
The new ToolTip for the Format Painter icon advertises a little-known feature of the Format Painter: You can copy a format to many different ranges. To do this, you follow these steps:
There is an easy way to make a copy of a worksheet. This method is better than creating a new worksheet and copying formats from the original sheet to the new sheet. Among its advantages are the fact that column widths and row heights are copied and page setup settings are copied.
To copy a worksheet within the current workbook, you follow these steps:
To copy a worksheet to a new workbook, you follow these steps:
18.119.116.102