29.05.2016 Views

Excel 2010 Tips and Tricks

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

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

114 Tip 49: Creating Custom Number Formats<br />

Parts of a number format string<br />

A custom format string enables you to specify different format codes for four categories of values:<br />

positive numbers, negative numbers, zero values, <strong>and</strong> text. You do so by separating the<br />

codes for each category with a semicolon. The codes are arranged in four sections, separated by<br />

semicolons:<br />

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

The following general guidelines determine how many of these four sections you need to specify:<br />

If your custom format string uses only one section, the format string applies to all values.<br />

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

section applies to negative values.<br />

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

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

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

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

types:<br />

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

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

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<br />

number is red, a zero is black, <strong>and</strong> text is blue. By the way, using the <strong>Excel</strong> conditional formatting<br />

feature is a much better way to apply color to cells based on their content.<br />

When you create a custom number format, don’t overlook the Sample box in the<br />

Number tab of the Format Cells dialog box. This box displays the value in the active<br />

cell by using the format string in the Type field. Be sure to test your custom number<br />

formats by using the following data: a positive value, a negative value, a zero value,<br />

<strong>and</strong> text. Often, creating a custom number format takes several attempts. Each time<br />

you edit a format string, it’s added to the list. When you finally get the correct format<br />

string, open the Format Cells dialog box one more time <strong>and</strong> delete your previous<br />

attempts.

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

Saved successfully!

Ooh no, something went wrong!