LAMBDA · Text

Pad ZIP LAMBDA

xl.pad.zip returns a 5-digit US ZIP as text. The number 2134 becomes 02134, with the leading zero restored.

Microsoft 365, Excel 2024, and Excel for the web. Excel 2021 does not have LAMBDA.

Syntax =xl.pad.zip(zip)

xl.pad.zip
=LAMBDA(zip,
  LET(
    digits, TEXT(zip, "0"),
    RIGHT("00000" & digits, 5)
  )
)

Arguments

NameRequiredWhat to pass
zipRequiredA ZIP code as a number or as text. The result is always text of length 5.

Examples

A Boston ZIP whose leading zero was lost

=xl.pad.zip(2134)

Result 02134

=RIGHT("00000"&TEXT(B1,"0"),5)B2
ZIP
AB
1Imported2134
2ZIP02134
A picture of the sheet, not a live calculator. The result is text. A later SUM will ignore it.

xl.pad.zip puts back the leading zero a CSV turned into a number. 2134 is the Boston ZIP 02134 once it is five characters of text. The result must stay text. Convert it to a number and the zero disappears again.

A ZIP that is already the text 02134 stays 02134, because padding 00000 in front and taking the right five characters is a no-op on a five-digit string.

Add it to the workbook

Copy the formula in the block above, including the line breaks. Choose Formulas, Name Manager, New. Set the name to xl.pad.zip, the scope to Workbook, and paste into Refers to. Excel Labs can do the same step: open the Advanced Formula Environment, add that name, and save it back to the workbook. A cell then calls =xl.pad.zip(...).

The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME? for LAMBDA even when it already has XLOOKUP, FILTER, or LET.

How it works

TEXT(zip, "0") makes a string of digits with no decimal places and no thousands separator. Five zeros are concatenated on the left. RIGHT keeps five characters. 2134 becomes 000002134, and the right five are 02134.

Limits

This is the five-digit ZIP, not ZIP+4. A longer digit string keeps its last five, which is wrong for a ZIP+4 you forgot to split. Letters fail TEXT’s numeric format and return an error.