Sub topic 2
Custom Format Codes and Digit Placeholders
Assume you can enter data, write basic formulas, select ranges, and use the Ribbon. Excel number formats change how a stored value appears. They do not normally change the stored value.
Custom format codes and digit placeholders
Open Format Cells, choose Custom, and enter a format code. The placeholders 0 and # both represent digits. A 0 forces a digit or zero. A # shows a digit only when needed.
00000The value 42 displays as 00042, while the stored value remains 42. A period sets the decimal position, and a comma separates thousands.
Format sections, colors, and conditions
A custom format can contain up to four sections separated by semicolons:
- Positive numbers
- Negative numbers
- Zero
- Text
#,##0.00;[Red]-#,##0.00;0.00;@This format shows positive and negative numbers with two decimal places, displays negatives in red, and leaves text unchanged. Conditions in brackets can replace the usual section order, such as [>=1000]0.0,"K".
Showing thousands and millions with commas
A comma after a digit placeholder scales the displayed value by 1,000. Two commas scale it by 1,000,000. Quoted text adds a label.
0.0,,"M"The value 1,234,567 displays as 1.2M.
Text format and leading zeros
Use @ to represent text in a custom format. To display identifiers with fixed width, use zero placeholders. This is useful for account codes and product IDs, but it does not turn text into a number.
Dates and times as serial numbers
Excel stores a date as a serial number: the whole-number part counts days from the workbook’s date system. Time is the fractional part of a day. Therefore, 0.5 represents noon.
=DATE(2024,1,1)This formula returns the date’s serial value under the default 1900 date system. Applying a date format changes its appearance.
Date formats and date codes
Common date codes include d for day, m for month, and y for year. Repeating a code adds digits, such as mm for a two-digit month and yyyy for a four-digit year.
yyyy-mm-ddUse h, mm, and ss for time. Be careful: m can mean month or minutes depending on its position near hour codes.
Exercise
What does the format 00000 do to the stored value 42?
Show answer
It displays 42 as 00042 without changing the stored value.