A CSV of guest addresses turned the Boston ZIP 02134 into the number 2134. The leading zero was never stored. A custom format of 00000 can paint that zero back on screen, and the cell still holds 2134. The next sort, the next file save to CSV, or a lookup against the text 02134 uses the number.
The guest list that keeps these codes is the wedding guest list. Maria Lopez is mailed as 02134.
TEXT puts the zero in the value
TEXT turns the number into text with a format code. "00000" means five digits, with zeros on the left if the number has fewer.
=TEXT(B1,"00000")| A | B | |
|---|---|---|
| 1 | Imported | 2134 |
| 2 | TEXT | 02134 |
| 3 | Length of TEXT | 5 |
| 4 | Length of the number | 4 |
| 5 | Excel 2010 | 02134 |
=TEXT(2134, "00000")
=LEN(TEXT(2134, "00000"))
=LEN(2134)
=RIGHT("00000"&TEXT(2134, "0"), 5)
Those results are 02134, 5, 4, and 02134. TEXT is in every current Excel. The result is text, so SUM ignores it. That is the right outcome for a ZIP column. Adding ZIP codes was never a total.
The last formula is the body of xl.pad.zip. Five zeros are concatenated on the left of the digits, and RIGHT keeps five characters. 2134 becomes 000002134, and the right five are 02134.
=xl.pad.zip(2134)
That returns 02134. The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME?. The RIGHT formula is the same five characters in Excel 2010.
A code that is already the text 02134 stays 02134. Padding 00000 in front of a five-character string and taking the right five is the same string.
The format that only changes the paint
Select the column, choose Format Cells, Custom, and type 00000. The number 2134 then displays as 02134. The formula bar still shows 2134. LEN of that cell is 4. A VLOOKUP or XLOOKUP for the text 02134 does not match it.
Set the column to Text before you paste, if you still have the original file. After the zero is gone, TEXT or the RIGHT formula is what writes it back. Formatting the cell afterward does not.
What counts as a ZIP shape
xl.is.zip checks two shapes: five digits, or five digits, a hyphen, and four digits. It does not check the Postal Service file. A code can have the right shape and still be unassigned.
=xl.is.zip(B1)| A | B | |
|---|---|---|
| 1 | Five digits | 02134 |
| 2 | Valid | TRUE |
| 3 | ZIP+4 | 02134-1234 |
| 4 | Valid | TRUE |
| 5 | Short | 7870 |
| 6 | Valid | FALSE |
=xl.is.zip("02134")
=xl.is.zip("02134-1234")
=xl.is.zip("7870")
=xl.is.zip("78701 1234")
The first two are TRUE. 7870 is FALSE. A space instead of the hyphen is FALSE. The ZIP+4 on this sheet is text. You cannot store the hyphen in a numeric cell and then ask TEXT to invent it.
The same check against the imported number fails, because 2134 has four digits. Austin’s 78701 never lost a zero, and it passes once it is text.
=xl.is.zip(B1)| A | B | |
|---|---|---|
| 1 | Imported | 2134 |
| 2 | Valid as imported | FALSE |
| 3 | Padded | 02134 |
| 4 | Valid after pad | TRUE |
| 5 | Austin | 78701 |
| 6 | Valid | TRUE |
=xl.is.zip(2134)
=xl.is.zip(TEXT(2134, "00000"))
=xl.is.zip("78701")
Those results are FALSE, TRUE, and TRUE. Pad first when the source was a number. The name uses VALUE on the characters, so a four-digit number is a four-digit string after Excel coerces it.
xl.pad.zip keeps five digits. Hand it a ZIP+4 that was stored as the number 21341234 and it keeps the last five of that digit string, which is not the ZIP. Split the five-digit part before you pad. On text that still has the hyphen, the five-digit part is the left five characters:
=LEFT("02134-1234", 5)
=xl.is.zip("02134-1234")
Those results are 02134 and TRUE.