Skip to content

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.

RowABC
1PartWhat it doesWith 1250 in the cell
20a digit, shown as 0 when there isn't one00000 shows 01250
3#a digit, shown only when it's needed#,##0 shows 1,250
4, after the digitsdivides what you see by 1,0000.0, shows 1.3
5"text"text, shown as typed0" 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 #,##0;-#,##0; hides zeros.

Example

The monthly change in units sold sits in C2:C5. With the code +#,##0;-#,##0;"no change", each value takes the section for its sign:

Positives take the first section, negatives the second and zero the third. The code has no fourth section, so the text in C5 shows as typed.

Common mistakes

  • 0.0,"M" shows 2,500,000 as 2500.0M. Each comma at the end divides by 1,000, so millions need two: 0.0,,"M".
  • Leaving the minus sign out of a negative section hides it: #,##0;[Red]#,##0 shows -730 as a red 730.
  • A code changes only the look. 00042 from a 00000 code 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

  • 0 pads 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

Premium

4 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.