18.11.2014 Views

Microsoft Office

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using Custom Number Formats 24<br />

TIP<br />

Custom number formats are stored with the workbook in which they are defined. To make the<br />

custom format available in a different workbook, you can just copy a cell that uses the custom<br />

format to the other workbook.<br />

You construct a number format by specifying a series of codes as a number format string. You enter this code<br />

sequence in the Type field after you select the Custom category on the Number tab in the Format Cells dialog<br />

box. Here’s an example of a simple number format code:<br />

0.000<br />

This code consists of placeholders and a decimal point; it tells Excel to display the value with three digits to<br />

the right of the decimal place. Here’s another example:<br />

00000<br />

This custom number format has five placeholders and displays the value with five digits (no decimal point).<br />

This format is good to use when the cell holds a five-digit Zip Code. (In fact, this is the code actually used<br />

by the Zip Code format in the Special category.) When you format the cell with this number format and<br />

then enter a Zip Code, such as 06604 (Bridgeport, CT), the value is displayed with the leading zero. If you<br />

enter this number into a cell with the General number format, it displays 6604 (no leading zero).<br />

Scroll through the list of number formats in the Custom category in the Format Cells dialog box to see<br />

many more examples. In many cases, you can use one of these codes as a starting point, and you’ll only<br />

need to customize it slightly.<br />

ON the CD-ROM<br />

The companion CD-ROM contains a workbook with many custom number format examples.<br />

The file is named number formats.xlsx.<br />

Parts of a number format string<br />

A custom format string can have up to four sections, which enables you to specify different format codes for<br />

positive numbers, negative numbers, zero values, and text. You do so by separating the codes with a semicolon.<br />

The codes are arranged in the following order:<br />

Positive format; Negative format; Zero format; Text format<br />

If you don’t use all four sections of a format string, Excel interprets the format string as follows:<br />

n<br />

n<br />

n<br />

If you use only one section, the format string applies to all types of entries.<br />

If you use two sections, the first section applies to positive values and zeros, and the second section<br />

applies to negative values.<br />

If you use three sections, the first section applies to positive values, the second section applies to<br />

negative values, and the third section applies to zeros.<br />

n If you use all four sections, the last section applies to text stored in the cell.<br />

The following is an example of a custom number format that specifies a different format for each of these<br />

types:<br />

[Green]General;[Red]General;[Black]General;[Blue]General<br />

This custom number format example takes advantage of the fact that colors have special codes. A cell formatted<br />

with this custom number format displays its contents in a different color, depending on the value.<br />

When a cell is formatted with this custom number format, a positive number is green, a negative number is<br />

red, a zero is black, and text is blue.<br />

469

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!