O'Reilly logo

Excel 2003 for Starters: The Missing Manual by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Formatting Worksheets

Creating a basic worksheet is only the first step toward mastering Excel. If you plan to print your worksheet, email it to colleagues, or show it off to friends, you need to think about whether you've formatted your worksheet in a viewer-friendly way. A careful use of color, shading, borders, and fonts can make the difference between a messy glob of data and a worksheet that's easy to work with and understand.

But formatting isn't just about deciding, say, where and how to make your text bold. Excel also lets you control the way numerical values are formatted. In fact, there are really two fundamental aspects of formatting in any worksheet:

  • Cell appearance. Cell appearance includes cosmetic details like color, typeface, alignment, and borders. When most people think of formatting, they think of cell appearance first.

  • Cell values. Cell value formatting controls the way Excel displays numbers, dates, and times. For numbers, cell formatting includes details like whether to use scientific notation, the number of decimal places Excel displays, and the use of currency symbols, percent signs, and commas. With dates, cell value formatting determines what parts of the date are shown in the cell, and in what order.

In many ways, cell value formatting is more significant than cell appearance, because cell value formatting can change the meaning of your data. For example, even though 45%, $0.45, and 0.450 are all the same number, your spreadsheet readers will see a failing test score, a cheap price for chewing gum, and a world-class batting average, respectively. Color and alignment can't hope to compete.

Tip

Keep in mind that regardless of how you format your cell values, Excel maintains an unalterable value for every number you type in. For more on how Excel internally stores numbers, see the box on Section 4.1.1.7.

In this chapter, you'll learn about cell value formatting, and then unleash your inner artist with cell appearance formatting. Finally, you'll learn the most helpful ways to use formatting to improve a worksheet's readability and how to save time with nifty features like AutoFormat, styles, and conditional formatting.

Formatting Cell Values

Cell value formatting is one aspect of worksheet design you don't want to ignore, because the values Excel stores can differ wildly from the numbers that it displays in the worksheet, as shown in Figure 4-1. In many cases, it makes sense to have the numbers that appear in your worksheet differ from Excel's underlying values, since a worksheet that's displaying numbers to, say, 13 decimal places, can look pretty cluttered.

Each of the cells B2, B3, and B4 contains the same number: 5.18518518518519. In the Formula bar, Excel will always display the exact number it's storing, as you see here with cell B2. However, in the worksheet itself, each cell's appearance differs depending on how you've formatted it.

Figure 4-1. Each of the cells B2, B3, and B4 contains the same number: 5.18518518518519. In the Formula bar, Excel will always display the exact number it's storing, as you see here with cell B2. However, in the worksheet itself, each cell's appearance differs depending on how you've formatted it.

To format a cell's value, follow these steps:

  1. Select the cells you want to format.

    You can apply formatting to individual cells or to a collection of cells. Usually, you'll want to format an entire column at once, because all the values in a column typically contain the same type of data. Remember, to select a column, you simply need to click the column header (the gray box at the top with the column letter).

    Note

    Technically, your average numeric column contains two types of data: the values you're storing within the actual cells and the column title in the topmost cell (where the title text is). However, you don't need to worry about unintentionally formatting the column title because number formats are applied only to numeric cells (cells that contain dates, times, or numbers). Excel doesn't use the number format for the column title cell because the column title cell contains text.

  2. Select Format → Cells, or just right-click the selection and choose Format Cells.

    In either case, the Format Cells dialog box appears, as shown in Figure 4-2.

  3. Set the format options you want, and then click OK to apply them.

    The options in the Number tab let you choose how Excel translates the cell value into a display value. (Number formatting choices are covered in the next section on Section 4.1.1.) The Alignment, Font, Border, and Patterns tabs are for cell appearance formatting, which is covered later in this chapter. (The Protection tab lets you hide formulas and lock your worksheet to prevent changes.)

Note

Once you apply formatting to a cell, it retains that formatting even if you clear the cell's contents (by selecting it and pressing Delete). In addition, formatting is part of a cell copy, so if you copy cell A1 to cell A2, Excel copies the formatting right along with the content. Formatting includes both cell value formatting and cell appearance.

The only way to remove the formatting is to highlight the cell and select Edit → Clear → Formats. This command removes the formatting, restoring the cell to its original, General number format (which you'll learn more about next), but doesn't remove any of the cell's content.

The Format Cells dialog box provides one-stop shopping for cell value and cell appearance formatting.

Figure 4-2. The Format Cells dialog box provides one-stop shopping for cell value and cell appearance formatting.

Formatting Numbers

The Number tab in the Format Cells dialog box lets you control how Excel displays numeric data in a cell. Excel gives you a lengthy list of predefined formats (shown in Figure 4-3), and it also lets you design your own formats. Remember, Excel uses number formats when the cell contains numeric information only. Otherwise, Excel simply ignores the number format (although the format is still there; Excel will use it if you change the cell content to a number, date, or time).

A good way to learn about the different number formats is to choose a new number format (such as Currency) from the Format Cells dialog box's Category list, as shown in Figure 4-3. When you do so, the Sample area of the dialog box shows how the number will be displayed if you apply that format. Excel also offers additional options you can use to customize the format. For example, if you choose the Currency format, Excel offers a list of currency symbols you can pick from—everything from dollars to kroner. To apply a format, just select the format and then click OK.

Here, the formatting category is Currency. The Sample area shows how the cell value—333—will appear in the worksheet: as $333.00, with two decimal places and a dollar sign. Clicking the Symbol list lets you choose another currency symbol—for example, English pounds or Jamaican dollars. To apply the format, click OK.

Figure 4-3. Here, the formatting category is Currency. The Sample area shows how the cell value—333—will appear in the worksheet: as $333.00, with two decimal places and a dollar sign. Clicking the Symbol list lets you choose another currency symbol—for example, English pounds or Jamaican dollars. To apply the format, click OK.

When you create a new spreadsheet, every cell starts out with the same number format: General. This format comes with a couple of basic rules:

  • If a number has any decimal places, Excel displays them, provided they fit in the column. If there are more decimal places than Excel can display, it leaves out the ones that don't fit. (It rounds up the last displayed digit, when appropriate). If you change a column width, Excel automatically adjusts the number of digits it displays.

  • Excel removes leading and trailing zeros. Thus, 004.00 becomes 4. The only exception to this rule occurs with numbers between -1 and 1, which retain the 0 before the decimal point. For example, Excel displays the number .42 as 0.42.

As you saw in Chapter 2, the way you type in a number can change a cell's formatting. For example, if you type in a number with a currency symbol, the number format of the cell changes automatically to Currency. Similarly, if you type in three numbers separated by dashes (-) or backward slashes (/), Excel assumes you're typing in a date and adjusts the number format to Date.

It's nice that Excel tries to be so helpful—but some things are best left up to people, not software. Rather than rely on this automatic process (especially when currency is involved), it's far better just to type in ordinary numbers and set the formatting explicitly for the whole column. This approach prevents you from having different formatting in different cells (which can confuse even the sharpest spreadsheet reader), and it makes sure you get exactly the formatting and precision you want. You can apply formatting to the column before or after you type in the numbers. And it doesn't matter if a cell is currently empty; Excel still keeps track of the number format you've applied.

Most of the spreadsheets you'll create will probably contain numbers in some form or fashion. So the following sections give a quick tour of the predefined number formats available on the Number tab in the Format Cells dialog box. Figure 4-4 gives you an overview of how different number formats affect similar numbers.

General

The General format is Excel's standard number format; it applies no special formatting other than the basic rules described at the beginning of this chapter. General is the only number format (other than Text) that doesn't limit your data to a fixed number of decimal places. That means if you want to display numbers that differ wildly in precision (like 0.5, 12.334, and 0.120986398), you can do so using the General format. On the other hand, if your numbers have a similar degree of precision (for example, if you're logging the number of hours of TV you watch each day), Number format makes more sense.

Each column contains the same list of numbers. Although this worksheet shows an example for each number format (except the less-frequently-used scientific and time categories), it doesn't show all your options. Each number format has its own settings—like the number of decimal places—that affect how Excel displays data.

Figure 4-4. Each column contains the same list of numbers. Although this worksheet shows an example for each number format (except the less-frequently-used scientific and time categories), it doesn't show all your options. Each number format has its own settings—like the number of decimal places—that affect how Excel displays data.

Number

The Number format is like the General format, but with three refinements. First, the Number format uses a fixed number of decimal places (which you set). That means that the decimal point always lines up (assuming you've formatted an entire column). The Number format also lets you use commas as a separator between groups of three digits, which is handy if you're working with really long numbers. Finally, you can choose to have negative numbers displayed with the negative sign, in parentheses, or in red lettering.

Currency

The Currency format closely matches the Number format, with two differences. First, you can choose a currency symbol (like the dollar sign, pound symbol, Euro symbol, and so on) from an extensive list; when you do, Excel automatically displays the currency symbol before the number. Second, the Currency format always includes commas. The Currency format also supports a fixed number of decimal places (chosen by you), and it lets you customize how negative numbers are displayed.

Accounting

The Accounting format is modeled on the Currency format. It also lets you choose a currency symbol, uses commas, and has a fixed number of decimal places. The difference is that the Accounting format uses a slightly different alignment. The currency symbol always appears at the far left of the cell (away from the number), and Excel always adds an extra space to pad the right side of the cell. Also, the Accounting format always shows negative numbers in parentheses, which is an accounting standard. Finally, Excel never shows the number 0 when using the Accounting format; instead of a zero, it displays a dash (-).

Percentage

The Percentage format displays fractional numbers as percentages. For example, if you type in 0.5, that translates to 50%. You can choose the number of decimal places to display.

There's one trick to watch out for with the Percentage format. If you forget to start your number with a decimal, Excel quietly "corrects" your numbers. For example, if you type 4 into a cell that uses the Percentage format, Excel interprets the 4 as 4%. As a result, it actually stores the value 0.04. A side effect of this quirkiness is that if you want to store percentages larger than 100%, you can't type them in as decimals. For example, to store 200%, you need to type in 200 (not 2.00).

Fraction

The Fraction format displays your number as a fraction instead of a number with decimal places. The Fraction format doesn't mean you have to type in the number as a fraction (although you can if you want by using the forward slash, like 3/4). Instead it means that Excel automatically converts any number you type in and displays it as a fraction. So, for example, to have 1/4 appear, you can either type in .25 or 1/4.

Lots of folks use the Fraction format for stock market quotes, but it's also handy for certain types of measurements (like weights, temperatures, and recipes). When using the Fraction format, Excel does its best to calculate the closest fraction, which depends on a few factors, including whether an exact match exists (typing in .5 will always get you 1/2, for example) and what type of precision level you've picked when selecting the Fraction formatting.

You can choose to have fractions with three digits (for example, 100/200), two digits (10/20), or just one digit (1/2), using the top three choices in the Type list. For example, if you type in the number 0.51, Excel shows it as 1/2 in one-digit mode, and the more precise 51/100 in three-digit mode. In some cases, you may want all numbers to use the same denominator (the bottom number in the fraction) so that it's easy to compare different numbers. In this case, you can choose to show all fractions as halves (with a denominator of 2), quarters (a denominator of 4), eighths (8), sixteenths (16), tenths (10), and hundredths (100). For example, the number 0.51 would be shown as 2/4 if you chose quarters.

Tip

You might feel like pulling your hair out in tufts when you're trying to type a fraction into Excel, and Excel keeps converting your fraction to a date (both use slashes). To prevent this confusion, always start by typing 0 and then a space. For example, instead of typing 2/3, type in 0 2/3 (which means zero and two-thirds). If you have a whole number and a fraction, like 1 2/3, you'll also be able to duck the date confusion.

Scientific

The Scientific format displays numbers using scientific notation, which is ideal if you ever find yourself needing to handle numbers that range widely in size (like 0.0003 and 300) in the same column. Scientific notation displays the first non-zero digit of a number, followed by a fixed number of digits, and then indicates what power of 10 that number needs to be multiplied by to generate the original number. For example, 0.0003 becomes 3.00 10-4 (displayed in Excel as 3.00E-04). The number 300, on the other hand, becomes 3.00 102 (displayed in Excel as 3.00E02). Scientists—surprise, surprise—like the Scientific format for doing things like recording experimental data or creating mathematical models to predict when an incoming meteor will graze Earth. Most of the rest of us can safely skip the Scientific format.

Text

Few people use the Text format for numbers, but it's certainly possible to do so. The Text format simply displays a number as though it were text, although you can still perform calculations with it. Excel shows the number exactly as it's stored internally, positioning it against the left edge of the column. You can get the same effect by placing an apostrophe before the number (although that approach won't let you use the number in calculations).

Formatting Dates and Times

To format dates and times, in the Format Cells dialog box (Format → Cells), shown in Figure 4-5, choose Date or Time from the column on the left and then choose the format from the list on the right. Date and Time both provide a slew of options. You can use everything from compact styles like 3/13/05 to longer formats that include the day of the week, like Sunday, March 13, 2005. You can choose a format that modifies the date's appearance depending on the regional settings of the computer viewing the Excel file (handy if you live in Baton Rouge and want your boss in Bangkok and your employees in Glasgow to view your worksheet), or you can choose a fixed date format. When using a fixed date format, you don't have to stick to the U.S. standard. Instead, choose the locale (geographic location) you want from the Locale listbox. Each locale—from Albanian to Vietnamese—provides its own set of customized date formats.

In a world of clock-watchers, it's no surprise that Excel offers dozens of different ways to format dates and times. You can choose between formats that modify the date's appearance depending on the regional settings of the computer viewing the Excel file, or you can choose a fixed date format from the Locale listbox.

Figure 4-5. In a world of clock-watchers, it's no surprise that Excel offers dozens of different ways to format dates and times. You can choose between formats that modify the date's appearance depending on the regional settings of the computer viewing the Excel file, or you can choose a fixed date format from the Locale listbox.

Time formats give you a similar range of options, including the ability to use a 12-hour or 24-hour clock, show seconds, show fractional seconds, and include the date information.

Excel offers two types of date and time formats:

  • Formats that take the regional settings of the computer you're using into account. With these formats, dates display differently depending on the computer that's running Excel. This choice is a good one because it lets everyone see dates just the way they want to, no matter where in the world they are. No more time-consuming Brits-vs.-Yanks arguments about whether the "real" way to order a date is month-day-year or day-month-year.

  • Formats that ignore the regional settings of individual computers. These formats define a fixed pattern for month, day, year, and time components, and display date-related information in exactly the same way on all computers. If you need to make sure a date is in a certain format, no ifs, ands, or buts, you should use this choice.

The first type (date and time formats that rely on a computer's regional settings) is the quickest to set. It includes just two date formats (a compact number-only format and a long, more descriptive format) and a single time format. You find these formats at the top of the Type list with an asterisk next to them.

Setting the second type (date and time formats that are independent of a computer's regional settings) takes a bit more doing. To choose one of these formats, you first select a geographical region from the Locale list, and then you select the appropriate date or time format. Some examples of locales include "English (United States)," "English (United Kingdom)," and "Arabic(Iraq)."

If you type in a date without specifically formatting the cell, Excel usually uses the short, region-specific date format. That means that the order of the month and year vary depending on the regional settings of your computer (or, if it's your bookie who's looking at your worksheet, your bookie's computer). But if you incorporate the month name (for example, January 1, 2005), instead of the month number (for example, 1/1/2005), Excel uses a compromise date format that includes a month abbreviation, like 1-Jan-2005.

Tip

You may remember from Chapter 2 that Excel stores a date internally as the cumulative number of days that have elapsed since a certain long-ago date that varies by operating system. If you're curious, you can take a peek at this internal number using the Format Cells dialog box. First, type in your date. Then, format the cell using one of the number formats (like General or Number). The underlying date number appears in your worksheet where the date used to be.

Special Formats for Special Numbers

There are some types of numeric information that you wouldn't ever want to perform mathematical operations with. For example, it's hard to image a situation where you'd want to add or multiply phone numbers or Social Security numbers.

So when you're typing in these kinds of numbers, you can format them as plain old text. For example, you could type in the text (555) 123-4567 to represent a phone number. Because there are parentheses and a dash (-), Excel won't interpret this information as a number. Or, you could just precede your value with an apostrophe (') to explicitly tell Excel that it should be treated as text.

But whichever solution you choose, you're potentially creating more work for yourself. Why? Because you have to type in the parentheses and the dash (or the apostrophe) for each phone number you type in. You also increase the likelihood of creating inconsistently formatted numbers, especially if you're typing in a long list of them. For example, careful as you are, some phone numbers may end up in slightly similar but somewhat different formats, like 555-123-4567 and (555)1234567.

To avoid these problems, apply Excel's Special number format, as shown in Figure 4-6, which converts numbers into common patterns. And lucky you: one of the Type options in the Special number format is Phone Number (other formats are for Zip codes and Social Security numbers).

After you apply the special Phone Number format to a cell, all you do is type in a series of digits, such as 5551234567; Excel automatically converts the digits to the proper phone number style—(555) 123-4567—without your having to type in all those pesky parentheses and dashes.

The Special format is a good idea, but it's limited because Excel only provides a small set of special types that you can use. However, there's no reason you can't handle similar problems by creating your own custom formats, covered extensively in Excel: The Missing Manual.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required