Write your own number formats
Number formats9 minPremium
Builds on Show money with number, currency and accounting formats.
A sales operations analyst in Munich builds a one-page pipeline report. Order numbers have to show six digits, the amounts are too long for the narrow columns, and losses in the variance column should show in red.
How it works
When no built-in format fits, write a code. Open Format Cells (Ctrl1, or Cmd1 on a Mac), choose Custom and type the code in the Type box. The cell keeps its value; the code only decides how it looks.
| Row | A | B | C |
|---|---|---|---|
| 1 | Part | What it does | With 1250 in the cell |
| 2 | 0 | a digit, shown as 0 when there isn't one | 00000 shows 01250 |
| 3 | # | a digit, shown only when it's needed | #, shows 1,250 |
| 4 | , after the digits | divides what you see by 1,000 | 0.0, shows 1.3 |
| 5 | "text" | text, shown as typed | 0" kg" shows 1250 kg |
| 6 | [Red] | a color for that part of the code | [Red]0 shows 1250 in red |
A code can have up to four sections, separated by semicolons, in this order: positive; negative; zero; text. With two sections, the first covers positive numbers and zero and the second covers negatives. In a negative section the minus sign is yours to write: Excel shows the number without its sign and adds only what the section says. A section left empty shows nothing, so #, hides zeros.
Example
The monthly change in units sold sits in C2:C5. With the code +#,, each value takes the section for its sign:
C5 shows as typed.Common mistakes
0.0,shows 2,500,000 as 2500.0M. Each comma at the end divides by 1,000, so millions need two:"M" 0.0,., "M" - Leaving the minus sign out of a negative section hides it:
#,shows -730 as a red 730.##0; [Red]#, ##0 - A code changes only the look. 00042 from a
00000code is still the number 42, so a lookup for the text "00042" won't find it. - Letters such as d, m, y, h and s are codes themselves. Put units in quotation marks:
0.0" m"for meters.
In short
0pads with zeros,#shows only the digits needed, and a comma at the end divides by 1,000.- Sections run positive; negative; zero; text, and a color in square brackets colors one section.
- The value never changes, only the look.
Practice
Premium4 exercises: 3 number formats and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in