Appendix B
Using Custom Number Formats

Although Excel provides a good variety of built-in number formats, you may find that none of these suits your needs. This appendix describes how to create custom number formats and provides many examples.

About Number Formatting

By default, all cells use the General number format. This is basically a “what you type is what you get” format. If the cell is not wide enough to show the entire number, the General format rounds numbers with decimals and uses scientific notation for large numbers. In many cases, you may want to format a cell with something other than the General number format.

The key thing to remember about number formatting is that it affects only how a value is displayed. The actual number remains intact, and any formulas that use a formatted number use the actual number.

One more thing to keep in mind: if you use Excel’s Find and Replace dialog box (choose Home ➜ Editing ➜ Find & Select ➜ Find), characters that are displayed are a result of number formatting (for example, a currency symbol) and are not searchable by default. To locate information based on formatting, use the Search in Value option in the Find and Replace dialog box.

Automatic number formatting

Excel is smart enough to perform some formatting for you automatically. For example, if you enter 12.3% into a cell, Excel knows that you want to use a percentage format and applies it automatically. If you use commas to separate thousands (such as 123,456), Excel applies comma formatting for you. And if you precede your value with a currency symbol, Excel formats the cell for currency.

Excel automatically applies a built-in number format to a cell based on the following criteria:

  • If a number contains a slash (/), it may be converted to a date format or a fraction format.
  • If a number contains a hyphen (-), it may be converted to a date format.
  • If a number contains a colon (:), or is followed by a space and the letter A or P (uppercase or lowercase), it may be converted to a time format.
  • If a number contains the letter E (uppercase or lowercase), it may be converted to scientific notation (also known as exponential format). If the number doesn’t fit into the column width, it may also be converted to this format.

Formatting numbers by using the Ribbon

The Number group on the Home tab of the Ribbon contains several controls that enable you to apply common number formats quickly. The Number Format drop-down control gives you quick access to 11 common number formats. In addition, the Number group contains some buttons. When you click one of these buttons, the selected cells take on the specified number format. Table B.1 summarizes the formats that these buttons perform in the U.S. English version of Excel.

Table B.1 Number-Formatting Buttons on the Ribbon

Button Name Formatting Applied
Accounting Number Format Adds a dollar sign to the left, separates thousands with a comma, and displays the value with two digits to the right of the decimal point. This is a drop-down control, so you can select other common currency symbols.
Percent Style Displays the value as a percentage, with no decimal places. This button applies a style to the cell.
Comma Style Separates thousands with a comma and displays the value with two digits to the right of the decimal place. This button applies a style to the cell.
Increase Decimal Increases the number of digits to the right of the decimal point by one.
Decrease Decimal Decreases the number of digits to the right of the decimal point by one.

Using shortcut keys to format numbers

Another way to apply number formatting is to use shortcut keys. Table B.2 summarizes the shortcut key combinations that you can use to apply common number formatting to the selected cells or range. Notice that these are the shifted versions of the number keys along the top of a typical keyboard.

Table B.2 Number-Formatting Keyboard Shortcuts

Key Combination Formatting Applied
Ctrl+Shift+~ General number format (that is, unformatted values).
Ctrl+Shift+! Two decimal places, thousands separator, and a hyphen for negative values.
Ctrl+Shift+@ Time format with the hour, minute, and AM or PM.
Ctrl+Shift+# Date format with the day, month, and year.
Ctrl+Shift+$ Currency format with two decimal places. (Negative numbers appear in parentheses.)
Ctrl+Shift+% Percentage format with no decimal places.
Ctrl+Shift+^ Scientific notation number format with two decimal places.

Using the format cells dialog box to format numbers

For maximum control of number formatting, use the Number tab of the Format Cells dialog box. To access this dialog box

  • Click the dialog box selector in the Home ➜ Number group.
  • Choose Home ➜ Number ➜ Number Format ➜ More Number Formats.
  • Press Ctrl+1.

The Number tab of the Format Cells dialog box contains 12 categories of number formats from which to choose. When you select a category from the list box, the right side of the dialog box changes to display appropriate options.

Following is a list of the number-format categories along with some general comments:

  • General: The default format; it displays numbers as integers, as decimals, or in scientific notation if the value is too wide to fit into the cell.
  • Number: Enables you to specify the number of decimal places, whether to use your system thousands separator (for example, a comma) to separate thousands, and how to display negative numbers.
  • Currency: Enables you to specify the number of decimal places, to choose a currency symbol, and to display negative numbers. This format always uses the system thousands separator symbol (for example, a comma) to separate thousands.
  • Accounting: Differs from the Currency format in that the currency symbols always line up vertically, regardless of the number of digits displayed in the value.
  • Date: Enables you to choose from a variety of date formats and select the locale for your date formats.
  • Time: Enables you to choose from a number of time formats and select the locale for your time formats.
  • Percentage: Enables you to choose the number of decimal places; always displays a percent sign.
  • Fraction: Enables you to choose from among nine fraction formats.
  • Scientific: Displays numbers in exponential notation (with an E): 2.00E+05 = 200,000. You can choose the number of decimal places to display to the left of E.
  • Text: When applied to a value, causes Excel to treat the value as text (even if it looks like a value). This feature is useful for such items as numerical part numbers and credit card numbers.
  • Special: Contains additional number formats. The list varies, depending on the locale you choose. For the English (United States) locale, the formatting options are Zip Code, Zip Code +4, Phone Number, and Social Security Number.
  • Custom: Enables you to define custom number formats not included in any of the other categories.

Creating a Custom Number Format

The Custom category on the Number tab of the Format Cells dialog box (see Figure B.1) enables you to create number formats not included in any of the other categories. Excel gives you a great deal of flexibility in creating custom number formats. When you create a custom number format, it can be used to format any cells in the workbook. You can create as many custom number formats as you need.

Image described by caption.

Figure B.1 The Number tab of the Format Cells dialog box.

You construct a number format by specifying a series of codes as a number format string. You enter this code sequence in the Type field after you select the Custom category on the Number tab of the Format Cells dialog box. Here’s an example of a simple number format code:

0.000

This code consists of placeholders and a decimal point; it tells Excel to display the value with three digits to the right of the decimal place. Here’s another example:

00000

This custom number format has five placeholders and displays the value with five digits (no decimal point). This format is good to use when the cell holds a five-digit ZIP code. (In fact, this is the code actually used by the Zip Code format in the Special category.) When you format the cell with this number format and then enter a ZIP code, such as 06604 (Bridgeport, CT), the value is displayed with the leading zero. If you enter this number into a cell with the General number format, it displays 6604 (no leading zero).

Scroll through the list of number formats in the Custom category of the Format Cells dialog box to see many more examples. In many cases, you can use one of these codes as a starting point, and you’ll need to customize it only slightly.

Parts of a number format string

A custom format string can have up to four sections, which enables you to specify different format codes for positive numbers, negative numbers, zero values, and text. You do so by separating the codes with a semicolon. The codes are arranged in the following order:

Positive format; Negative format; Zero format; Text format

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

  • If you use only one section: The format string applies to all numeric types of entries.
  • If you use two sections: The first section applies to positive values and zeros, and the second section applies to negative values.
  • If you use three sections: The first section applies to positive values, the second section applies to negative values, and the third section applies to zeros.
  • If you use all four sections: The last section applies to text stored in the cell.

The following is an example of a custom number format that specifies a different format for each of these types:

[Green]General;[Red]General;[Black]General;[Blue]General

This custom number format example takes advantage of the fact that colors have special codes. A cell formatted with this custom number format displays its contents in a different color, depending on the value. When a cell is formatted with this custom number format, a positive number is green, a negative number is red, a zero is black, and text is blue.

Custom number format codes

Table B.3 lists the formatting codes available for custom formats, along with brief descriptions.

Table B.3 Codes Used to Create Custom Number Formats

Code Comments
General Displays the number in General format.
# Digit placeholder. Displays only significant digits and does not display insignificant zeros.
0 (zero) Digit placeholder. Displays insignificant zeros if a number has fewer digits than there are zeros in the format.
? Digit placeholder. Adds spaces for insignificant zeros on either side of the decimal point so that decimal points align when formatted with a fixed-width font. You can also use ? for fractions that have varying numbers of digits.
. Decimal point.
% Percentage.
, Thousands separator.
E- E+ e- e+ Scientific notation.
$ - + / ( ) : space Displays this character.
Displays the next character in the format.
* Repeats the next character, to fill the column width.
_ (underscore) Leaves a space equal to the width of the next character.
“text” Displays the text inside the double quotation marks.
@ Text placeholder.
[color] Displays the characters in the color specified. Can be any of the following text strings (not case sensitive): Black, Blue, Cyan, Green, Magenta, Red, White, or Yellow.
[Color n] Displays the corresponding color in the color palette, where n is a number from 0 to 56.
[condition value] Enables you to set your own criterion for each section of a number format.

Table B.4 lists the codes used to create custom formats for dates and times.

Table B.4 Codes Used in Creating Custom Formats for Dates and Times

Code Comments
m Displays the month as a number without leading zeros (1–12).
mm Displays the month as a number with leading zeros (01–12).
mmm Displays the month as an abbreviation (Jan–Dec).
mmmm Displays the month as a full name (January–December).
mmmmm Displays the first letter of the month (J–D).
d Displays the day as a number without leading zeros (1–31).
dd Displays the day as a number with leading zeros (01–31).
ddd Displays the day as an abbreviation (Sun–Sat).
dddd Displays the day as a full name (Sunday–Saturday).
yy or yyyy Displays the year as a two-digit number (00–99) or as a four-digit number (1900–9999).
h or hh Displays the hour as a number without leading zeros (0–23) or as a number with leading zeros (00–23).
m or mm When used with a colon in a time format, displays the minute as a number without leading zeros (0–59) or as a number with leading zeros (00–59).
s or ss Displays the second as a number without leading zeros (0-59) or as a number with leading zeros (00–59).
[ ] Displays hours greater than 24, or minutes or seconds greater than 60.
AM/PM Displays the hour using a 12-hour clock. If no AM/PM indicator is used, the hour uses a 24-hour clock.

Custom Number Format Examples

The remainder of this appendix consists of useful examples of custom number formats. You can use most of these format codes as-is. Others may require slight modification to meet your needs.

Scaling values

You can use a custom number format to scale a number. For example, if you work with very large numbers, you may want to display the numbers in thousands (that is, displaying 1,000,000 as 1,000). The actual number, of course, will be used in calculations that involve that cell. The formatting affects only how it displays.

Displaying values in thousands

The following format string displays values without the last three digits to the left of the decimal place, and no decimal places. In other words, the value appears as if it’s divided by 1,000 and rounded to no decimal places.

#,###,

A variation of this format string follows. A value with this number format appears as if it’s divided by 1,000 and rounded to two decimal places.

#,###.00,

Table B.5 shows examples of these number formats.

Table B.5 Examples of Displaying Values in Thousands

Value Number Format Display
123456 #,###, 123
1234565 #,###, 1,235
-323434 #,###, -323
123123.123 #,###, 123
499 #,###, (blank)
500 #,###, 1
123456 #,###.00, 123.46
1234565 #,###.00, 1,234.57
-323434 #,###.00, -323.43
123123.123 #,###.00, 123.12
499 #,###.00, .50
500 #,###.00, .50

Displaying values in hundreds

The following format string displays values in hundreds, with two decimal places. A value with this number format appears as if it’s divided by 100 and rounded to two decimal places.

0"."00

Table B.6 shows examples of these number formats.

Table B.6 Examples of Displaying Values in Hundreds

Value Number Format Display
546 0"."00 5.46
100 0"."00 1.00
9890 0"."00 98.90
500 0"."00 5.00
-500 0"."00 -5.00
0 0"."00 0.00

Displaying values in millions

The following format string displays values in millions, with no decimal places. A value with this number appears as if it’s divided by 1,000,000 and rounded to no decimal places.

#,###,,

A variation of this format string follows. A value with this number appears as if it’s divided by 1,000,000 and rounded to two decimal places.

#,###.00,,

Here’s another variation. This format string adds the letter M to the end of the value.

#,###,,"M"

The following format string is a bit more complex. It adds the letter M to the end of the value — and also displays negative values in parentheses as well as displaying zeros.

#,###.0,,"M"_);(#,###.0,,"M)";0.0"M"_)

Table B.7 shows examples of these format strings.

Table B.7 Examples of Displaying Values in Millions

Value Number Format Display
123456789 #,###,, 123
1.23457E+11 #,###,, 123,457
1000000 #,###,, 1
5000000 #,###,, 5
-5000000 #,###,, -5
0 #,###,, (blank)
123456789 #,###.00,, 123.46
1.23457E+11 #,###.00,, 123,457.00
1000000 #,###.00,, 1.00
5000000 #,###.00,, 5.00
-5000000 #,###.00,, -5.00
0 #,###.00,, .00
123456789 #,###,,"M" 123M
1.23457E+11 #,###,,"M" 123,457M
1000000 #,###,,"M" 1M
5000000 #,###,,"M" 5M
-5000000 #,###,,"M" -5M
0 #,###,,"M" M
123456789 #,###.0,,"M"_);(#,###.0,,"M)";0.0"M"_) 123.5M
1.23457E+11 #,###.0,,"M"_);(#,###.0,,"M)";0.0"M"_) 123,456.8M
1000000 #,###.0,,"M"_);(#,###.0,,"M)";0.0"M"_) 1.0M
5000000 #,###.0,,"M"_);(#,###.0,,"M)";0.0"M"_) 5.0M
-5000000 #,###.0,,"M"_);(#,###.0,,"M)";0.0"M"_) (5.0M)
0 #,###.0,,"M"_);(#,###.0,,"M)";0.0"M"_) 0.0M

Appending zeros to a value

The following format string displays a value with three additional zeros and no decimal places. A value with this number format appears as if it’s rounded to no decimal places and then multiplied by 1,000.

#",000"

Examples of this format string, plus a variation that adds six zeros, are shown in Table B.8.

Table B.8 Examples of Displaying a Value with Extra Zeros

Value Number Format Display
1 #",000" 1,000
1.5 #",000" 2,000
43 #",000" 43,000
-54 #",000" -54,000
5.5 #",000" 6,000
0.5 #",000,000" 1,000,000
0 #",000,000" ,000,000
1 #",000,000" 1,000,000
1.5 #",000,000" 2,000,000
43 #",000,000" 43,000,000
-54 #",000,000" -54,000,000
5.5 #",000,000" 6,000,000
0.5 #",000,000" 1,000,000

Hiding zeros

In the following format string, the third element of the string is empty, which causes zero-value cells to display as blank:

General;-General;

This format string uses the General format for positive and negative values. You can, of course, substitute any other format codes for the positive and negative parts of the format string.

Displaying leading zeros

To display leading zeros, create a custom number format that uses the 0 character. For example, if you want all numbers to display with ten digits, use the number format string that follows. Values with fewer than ten digits will display with leading zeros.

0000000000

You also can force all numbers to display with a fixed number of leading zeros. The format string that follows, for example, prepends three zeros to each number:

"000"#

Displaying fractions

Excel supports quite a few built-in fraction number formats. (Select the Fraction category from the Number tab of the Format Cells dialog box.) For example, to display the value .125 as a fraction with 8 as the denominator, select As Eighths (4/8) from the Type list.

You can use a custom format string to create other fractional formats. For example, the following format string displays a value in 50ths:

# ??/50

To display the fraction reduced to its lowest terms, use a question mark after the slash symbol. For example, the value 0.125 can be expressed as 2/16, and 2/16 can be reduced to 1/8. Here’s an example of a number format that displays the value as a fraction reduced to its simplest terms:

# ?/?

If you omit the leading hash mark, the value displays without a leading value. For example, the value 2.5 would display as 5/2 using this number format code:

?/?

The following format string displays a value in terms of fractional dollars. For example, the value 154.87 displays as 154 and 87/100 Dollars.

0 "and "??/100 "Dollars"

The following example displays the value in 16ths, with an appended double quotation mark. This format string is useful when you deal with inches (for example, 2/16).

# ??/16"

Displaying N/A for text

The following number format string uses General formatting for all cell entries except text. Text entries appear as N/A.

0.0;0.0;0.0;"N/A"

You can, of course, modify the format string to display specific formats for values. The following variation displays values with one decimal place:

0.0;0.0;0.0;"N/A"

Displaying text in quotes

The following format string displays numbers normally but surrounds text with double quotation marks:

General;General;General;"@"

Repeating a cell entry

The following number format is perhaps best suited as an April Fool’s gag played on an office mate. It displays the contents of the cell three times. For example, if the cell contains the text Budget, the cell displays Budget Budget Budget. If the cell contains the number 12, it displays as 12 12 12.

@ @ @

Displaying a negative sign on the right

The following format string displays negative values with the negative sign to the right of the number. Positive values have an additional space on the right, so both positive and negative numbers align properly on the right.

0.00_-;0.00-

To make the negative numbers more prominent, you can add a color code to the negative part of the number format string:

0.00_-;[Red]0.00-

Conditional number formatting

Conditional formatting refers to formatting that is applied based on the contents of a cell. Excel’s Conditional Formatting feature provides the most efficient way to perform conditional formatting of numbers, but you also can use custom number formats.

The following format string displays different text (no value), depending on the value in the cell. This format string essentially separates the numbers into three groups: less than or equal to 4, greater than or equal to 8, and other.

[<=4]"Low"* 0;[>=8]"High"* 0;"Medium"* 0

The following number format is useful for telephone numbers. Values greater than 9999999 (that is, numbers with area codes) are displayed as (xxx) xxx-xxxx. Other values (numbers without area codes) are displayed as xxx-xxxx.

[>9999999](000) 000-0000;000-0000

For U.S. ZIP codes, you might want to use the format string that follows. This displays ZIP codes using five digits. If the number is greater than 99999, it uses the ZIP-plus-four format (xxxxx-xxxx).

[>99999]00000-0000;00000

Coloring values

Custom number format strings can display the cell contents in various colors. The following format string, for example, displays positive numbers in red, negative numbers in green, zero values in black, and text in blue:

[Red]General;[Green]-General;[Black]General;[Blue]General

Following is another example of a format string that uses colors. Positive values display normally; negative numbers and text cause Error! to display in red.

General;[Red]"Error!";0;[Red]"Error!"

Using the following format string, values that are less than 2 display in red. Values greater than 4 display in green. Everything else (text, or values between 2 and 4) displays in black.

[Red][<2]General;[Green][>4]General;[Black]General

As seen in the preceding examples, Excel recognizes color names such as [Red] and [Blue]. It also can use other colors from the color palette, indexed by a number. The following format string, for example, displays the cell contents using the 16th color in the color palette:

[Color16]General

Formatting dates and times

When you enter a date into a cell, Excel formats the date using the system short date format. You can change this format using the Windows Control Panel (Regional and Language options).

Excel provides many useful built-in date and time formats. Table B.9 shows some other custom date and time formats that you may find useful. The first column of the table shows the date/time serial number.

Table B.9 Useful Custom Date and Time Formats

Value Number Format Display
41456 mmmm d, yyyy (dddd) July 1, 2013 (Monday)
41456 "It’s" dddd! It’s Monday!
41456 dddd, mm/dd/yyyy Monday, 07/01/2013
41456 "Month: "mmm Month: July
41456 General (m/d/yyyy) 41456 (7/4/2013)
0.345 h "Hours" 8 Hours
0.345 h:mm "o’clock" 8:16 o’clock
0.345 h:mm a/p"m" 8:16 am
0.78 h:mm a/p".m." 6:43 p.m.

Displaying text with numbers

The ability to display text with a value is one of the most useful benefits of using a custom number format. To add text, just create the number format string as usual (or use a built-in number format as a starting point) and put the text within quotation marks. The following number format string, for example, displays a value with the text (US Dollars) added to the end:

#,##0.00 "(US Dollars)"

Here’s another example that displays text before the number:

"Average: "0.00

If you use the preceding number format, you’ll find that the negative sign appears before the text for negative values. To display number signs properly, use this variation:

"Average: "0.00;"Average: "-0.00

The following format string displays a value with the words Dollars and Cents. For example, the number 123.45 displays as 123 Dollars and .45 Cents.

0 "Dollars and" .00 "Cents"

Displaying a zero with dashes

The following number format string displays zero values as a series of dashes:

#,##0.0;-###0.0;------

You can, of course, create lots of variations. For example, you can replace the six hyphens with any of the following:

<0>
-0-
~~
"<NULL>"
"[NULL]"

Using special symbols

Your number format strings can use special symbols, such as the copyright symbol, degree symbol, and so on.

The easiest way to insert a symbol into a number format string is to enter it into a cell. Copy the character and then paste it into your custom number format string (using Ctrl+V). Use the Insert ➜ Text ➜ Symbol command, which displays the Insert Symbol dialog box, to enter a special character into a cell.

Suppressing certain types of entries

You can use number formatting to hide certain types of entries. For example, the following format string displays text but not values:

;;

This format string displays values (with one decimal place) but not text or zeros:

0.0;-0.0;;

This format string displays everything except zeros (values display with one decimal place):

0.0;-0.0;;@

You can use the following format string to completely hide the contents of a cell:

;;;

Note that when the cell is activated, however, the cell’s contents are visible on the Formula bar.

Filling a cell with a repeating character

The asterisk (*) symbol specifies a repeating character in a number format string. The repeating character completely fills the cell and adjusts if the column width changes. The following format string, for example, displays the contents of a cell padded on the right with dashes:

General*-;-General*-;General*-;General*-

Displaying leading dots

The following custom number format is a variation on the accounting format. Using this number format displays the dollar sign on the left and the value on the right. The space in between is filled with dots.

($*.#,##0.00_);_($*.(#,##0.00);_($* "-"??_);_(@_)
..................Content has been hidden....................

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