Have you ever typed a number with one or more leading zeros, like 00123 and watched as Excel drops the leading zeros as soon as you press Enter.
Frustrating, isn’t it!
So how do you fix it?
There are 2 methods. One is better than the other for a quick set up and easy maintenance. There is also a third method which combines elements from each of the first two.
Feature Download: Grab 2 fantastic takeaways (both free). Watch a free video demonstrating everything discussed below and download a handy cheat sheet (printable reference) summarising all the key steps.
Method 1: Format the cells as text
- Before you enter any data, select the cells where the data is to be entered.
- Press CTRL 1. This is a keyboard shortcut to display the Format Cells dialog.
- On the Number tab, choose the TEXT category.
- Close the dialog.
Now, when you enter your data with leading zeros, the leading zeros remain and do not disappear when you press Enter.
A couple of things to watch out for:
- Text is left-aligned by default so you may need to re-align the data.
- If your data has already been entered (or downloaded), switching to a text format will not fix the data - there is a partial fix for this which is outlined in Method 3.
Method 2: Use custom formatting
- Select the cell range where the data will be entered (or has already been entered).
- Press CTRL 1 to display the Format Cells dialog.
- In the Number tab, choose the CUSTOM category.
- Custom formatting works with a system of place holders. For numbers, the primary place holders are:
If you have a 5 digit product code, enter 00000 into the 'Type' box. This will convert 123 to 00123, 1 to 00001 etc.If you have a phone number with a 4-digit area code followed by 2 sets of 4 digits, enter (0000) 000-000 into the 'Type' box. This will convert 0123456789 to (0123) 456-789.Close the dialog.
- '#' which represents an optional digit 0-9, and
- '0' (zero) which represents a mandatory digit 0-9 (this is what we need for leading zeros)
- Any punctuation you add is displayed as-is.
Figure 01: Create a custom format for an Australian mobile number
The new custom format will now be applied.
Phone numbers will now have the punctuation and spacing. For example, enter 0123456789 into a custom-formatted phone number cell (see above) and press Enter. It will automatically reformat to (0123) 456–789.
Numbers that previously dropped the leading zeros will now display the leading zeros. For example, enter 123 into a custom-formatted number cell (see above) and press Enter. The leading zero will be added automatically to display 00123.
Method 3: Expert Tip - Combine methods 1 and 2
If you import data into Excel that was exported from another program or website, the data is often formatted entirely as text.
Figure 02: Numbers stored as text
You can click the smart icon (see above), then choose Convert To Number but you still don’t have the leading zeroes!
An easy way to convert a lot of ‘text’ numbers to ‘numeric’ numbers (if that makes sense) and add leading zeroes is to follow this process (assume the ‘text’ numbers are in column A):
Figure 03: Numbers start in text format
Numbers start in text format[/caption]
- Insert a blank column, if necessary.
- In cell B1 type =A1*1 and press Enter. The result is the same number but in numeric format (notice that it is right-aligned).
Figure 04: Formula that converts 'text' number to 'numeric' number
- Copy the formula down.
- Select column B and assign the custom format to add the leading zeros as described above.
Figure 05: Select the entire column and set a custom format
- With column B still selected, COPY the data then PASTE SPECIAL as VALUES (using the right-click menu) to column B to overwrite the values, or PASTE SPECIAL directly over the original ‘text’ numbers in column A if your prefer.
Figure 06: Select the column of data, COPY, then PASTE SPECIAL the VALUES over the same cells
- Delete column B as it is now redundant.
I hope that gets you out of a fix. Add a comment below if this helped you.