Excel custom number formats

Excel custom number formats

Introduction

Number formats control how numbers are displayed in Excel. The key benefit of number formats is that they change how a number looks without changing any data. They are a great way to save time in Excel because they perform a huge amount of formatting automatically. As a bonus, they make worksheets look more consistent and professional.
Video: What is a number format

What can you do with custom number formats?

Custom number formats can control the display of numbers, dates, times, fractions, percentages, and other numeric values. Using custom formats, you can do things like format dates to show month names only, format large numbers in millions or thousands, and display negative numbers in red.
Sample custom number formats

Where can you use custom number formats?

Many areas in Excel support number formats. You can use them in tables, charts, pivot tables, formulas, and directly on the worksheet.
  • Worksheet - format cells dialog
  • Pivot Tables - via value field settings
  • Charts - data labels and axis options
  • Formulas - via the TEXT function

What is a number format?

A number format is a special code to control how a value is displayed in Excel. For example, the table below shows 7 different number formats applied to the same date, January 1, 2019:
InputCodeResult
1-Jan-2019yyyy2019
1-Jan-2019yy19
1-Jan-2019mmmJan
1-Jan-2019mmmmJanuary
1-Jan-2019d1
1-Jan-2019dddTue
1-Jan-2019ddddTuesday
The key thing to understand is that number formats change the way numeric values are displayed, but they do not change the actual values.

Where can you find number formats?

On the home tab of the ribbon, you'll find a menu of build-in number formats. Below this menu to the right, there is small button to access all number formats, including custom formats:
Number format menu on Home tab of Ribbon
This button opens the Format Cells dialog box. You'll find a complete list of number formats, organized by category, on the Number tab:
Format Cells dialog box on Number tab
Note: you can open Format Cells dialog box with the keyboard shortcut Control + 1.

General is default

By default, cells start with the General format applied. The display of numbers using the General number format is somewhat "fluid". Excel will display as many decimal places as space allows, and will round decimals and use scientific number format when space is limited. The screen below shows the same values in column B and D, but D is narrower and Excel makes adjustments on the fly.
General number format in narrow column

How to change number formats

You can select standard number formats (General, Number, Currency, Accounting, Short Date, Long Date, Time, Percentage, Fraction, Scientific, Text) on the home tab of the ribbon using the Number Format menu.
Note: As you enter data, Excel will sometimes change number formats automatically. For example if you enter a valid date, Excel will change to "Date" format. If you enter a percentage like 5%, Excel will change to Percentage, and so on.

Shortcuts for number formats

Excel provides a number of keyboard shortcuts for some common formats:
FormatShortcut
General formatCtrl Shift ~
Currency formatCtrl Shift $
Percentage formatCtrl Shift %
Scientific formatCtrl Shift ^
Date formatCtrl Shift #
Time formatCtrl Shift @
Custom formatsControl + 1
See also: 222 Excel Shortcuts for Windows and Mac

Where to enter custom formats

At the bottom of the predefined formats, you'll see a category called custom. The Custom category shows a list of codes you can use for custom number formats, along with an input area to enter codes manually in various combinations.
Custom category in format cells dialog box
When you select a code from the list, you'll see it appear in the Type input box. Here you can modify existing custom code, or to enter your own codes from scratch. Excel will show a small preview of the code applied to the first selected value above the input area.
Note: Custom number formats live in a workbook, not in Excel generally. If you copy a value formatted with a custom format from one workbook to another, the custom number format will be transferred into the workbook along with the value.

How to create a custom number format

To create custom number format follow this simple 4-step process:
  1. Select cell(s) with values you want to format
  2. Control + 1 > Numbers > Custom
  3. Enter codes and watch preview area to see result
  4. Press OK to save and apply 
Tip: if you want base your custom format on an existing format, first apply the base format, then click the "Custom" category and edit codes as you like.

How to edit a custom number format

You can't really edit a custom number format per se. When you change an existing custom number format, a new format is created and will appear in the list in the Custom category. You can use the Delete button to delete custom formats you no longer need.
Warning: there is no "undo" after deleting a custom number format!

Structure and Reference

Excel custom number formats have a specific structure. Each number format can have up to four sections, separated with semi-colons as follows:
Custom number format structure
This structure can make custom number formats look overwhelmingly complex. To read a custom number format, learn to spot the semi-colons and mentally parse the code into these sections:
  1. Positive values
  2. Negative values
  3. Zero values
  4. Text values

Not all sections required

Although a number format can include up to four sections, only one section is required. By default, the first section applies to positive numbers, the second section applies to negative numbers, the third section applies to zero values, and the forth section applies to text.
  • When only one format is provided, Excel will use that format for all values.
  • If you provide a number format with just two sections, the first section is used for positive numbers and zeros, and the second section is used for negative numbers.
  • To skip a section, include a semi-colon in the proper location, but don't specify a format code.

Characters that display natively

Some characters appear normally in a number format, while others require special handling. The following characters can be be used without any special handling:
CharacterComment
$Dollar
+-Plus, minus
()Parentheses
{}Curly braces
<>Less than, greater than
=Equal
:Colon
^Caret
'Apostrophe
/Forward slash
!Exclamation point
&Ampersand
~Tilde
 Space character

Escaping characters

Some characters won't work correctly in a custom number format without being escaped. For example, the asterisk (*), hash (#), and percent (%) characters can't be used directly in a custom number format – they won't appear in the result. The escape character in custom number formats is the backslash (\). By placing the backslash before the character, you can use them in custom number formats:
ValueCodeResult
100\#0#100
100\*0*100
100\%0%100

Placeholders

Certain characters have special meaning in custom number format codes. The following characters are key building blocks:
CharacterPurpose
0Display insignificant zeros
#Display significant digits
?Display aligned decimals
.Decimal point
,Thousands separator
*Repeat digit
_Add space
@Placeholder for text
Zero (0) is used to force the display of insignificant zeros when a number has fewer digits than than zeros in the format. For example, the custom format 0.00 will display zero as 0.00, 1.1 as 1.10 and .5 as 0.50.
Zero placeholder examples
Pound sign (#) is a placeholder for optional digits. When a number has fewer digits than # symbols in the format, nothing will be displayed. For example, the custom format #.## will display 1.15 as 1.15 and 1.1 as 1.1.
Pound placeholder examples
Question mark (?) is used to align digits. When a question mark occupies a place not needed in a number, a space will be added to maintain visual alignment. 
Question mark placeholder examples
Period (.) is a placeholder for the decimal point in a number. When a period is used in a custom number format, it will always be displayed, regardless of whether the number contains decimal values.
Comma (,) is a placeholder for the thousands separators in the number being displayed.  It can be used to define the behavior of digits in relation to the thousands or millions digits.
Comma placeholder examples
Asterisk (*) is used to repeat characters. The character immediately following an asterisk will be repeated to fill remaining space in a cell.
Asterisk placeholder examples
Underscore (_) is used to add space in a number format. The character immediately following an underscore character controls how much space to add. A common use of the underscore character is to add space to align positive and negative values when a number format is adding parentheses to negative numbers only. For example, the number format "0_);(0)" is adding a bit of space to the right of positive numbers so that they stay aligned with negative numbers, which are enclosed in parentheses.
Underscore placeholder examples
At (@) - placeholder for text. For example, the following number format will display text values in blue:
0;0;0;[Blue]@
See below for more information about using color.

Automatic rounding

It's important to understand the Excel will perform "visual rounding" with all custom number formats. When a number has more digits than placeholders on the right side of the decimal point, the number is rounded to the number of placeholders. When a number has more digits than placeholders on the left side of the decimal point, extra digits are displayed. This is a visual effect only; actual values are not modified.

Number formats for TEXT

To display both text along with numbers, enclose the text in double quotes ("").  You can use this  approach to append or prepend text strings in a custom number format, as shown in the table below.
ValueCodeResult
10General" units"10 units
100.0" units"10.0 units
5.50.0" feet"5.5 feet
300000" feet"30000 feet
95.2"Score: "0.0Score: 95.2
1-Jun"Date: "mmmm dDate: June 1

Number formats for DATES

Dates in Excel are just numbers, so you can use custom number formats to change the way they display. Excel many specific codes you can use to display components of a date in different ways. The screen below shows how Excel displays the date in D5, September 3, 2018, with a variety of custom number formats:
Number format codes for dates

Number formats for TIME

Times in Excel are fractional parts of a day. For example, 12:00 PM is 0.5, and 6:00 PM is 0.75. You can use the following codes in custom time formats to display components of a time in different ways. The screen below shows how Excel displays the time in D5, 9:35:07 AM, with a variety of custom number formats:
Number format codes for times
Note: m and mm can't be used alone in a custom number format since they conflict with the month number code in date format codes.

Number formats for ELAPSED TIME

Elapsed time is a special case and needs special handling. By using square brackets, Excel provides a special way to display elapsed hours, minutes, and seconds. The following screen shows how Excel displays elapsed time based on the value in D5, which represents 1.25 days:
Number format codes for elapsed time

Number formats for COLORS

Excel provides basic support for colors in custom number formats. The following 8 colors can be specified by name in a number format: [black] [white] [red][green] [blue] [yellow] [magenta] [cyan]. Color names must appear in brackets.
Custom number format with colors

Colors by index

In addition to color names, it's also possible to specify colors by an index number (Color1,Color2,Color3, etc.) The examples below are using the custom number format: [ColorX]0"▲▼", where X is a number between 1-56:
[Color1]0"▲▼" // black
[Color2]0"▲▼" // white
[Color3]0"▲▼" // red
[Color4]0"▲▼" // green
etc.
The triangle symbols have been added only to make the colors easier to see. The first image shows all 56 colors on a standard white background. The second image shows the same colors on a gray background. Note the first 8 colors shown correspond to the named color list above.
Custom number format colors on white
Custom number format colors on gray background

Apply number formats in a formula

Although most number formats are applied directly to cells in a worksheet, you can also apply number formats inside a formula with the TEXT function. For example, with a valid date in A1, the following formula will display the month name only:
=TEXT(A1,"mmmm")
The result of the TEXT function is always text, so you are free to concatenate the result of TEXT to other strings:
="The contract expires in "&TEXT(A1,"mmmm")
The screen below shows the number formats in column C being applied to numbers in column B using the TEXT function:
Applying number formats with the TEXT function

Conditionals

Custom number formats also up to two conditions, which are written in square brackets like [>100] or [<=100]. When you use conditionals in custom number formats, you override the standard [postive];[negative];[zero];[text] structure. For example, to display values below 100 in red, you can use:
[Red][<100]0;0
To display values greater than or equal to 100 in blue, you can extend the format like this:
[Red][<100]0;[Blue][>=100]0
Conditions with custom number formats
To apply more than two conditions, or to change other cell attributes, like fill color, etc. you'll need to switch to Conditional Formatting, which can can apply formatting with much more power and flexibility using formulas.

Plural text labels

You can use conditionals to add an "s" to labels greater than zero with a custom format like this:
[=1]0" day";0" days"
Custom number format for plural text

Telephone numbers

Custom number formats can also be used for telephone numbers, as shown in the screen below:
Custom number format for telephone numbers
Notice the third and forth examples use a conditional format to check for numbers that contain an area code. If you have data that contains phone numbers with hard-coded punctuation (parentheses, hyphens, etc.) you will need to clean the telephone numbers first so that they only contain numbers.

Hide all content

You can actually use a custom number format to hide all content in a cell. The code is simply three semi-colons and nothing else ;;;
To reveal the content again, you can use the keyboard shortcut Control + Shift + ~, which applies the General format.

Other resources

  • Developer Bryan Braun built a nice interactive tool for building custom number formats
#evba #etipfree #eama #kingexcel
📤How to Download ebooks: https://www.evba.info/2020/02/instructions-for-downloading-documents.html?m=1
Powered by Blogger.