Imports often strip leading zeros, leaving IDs of different lengths. REPT repeats a zero as many times as the ID is short of the target width, and the ampersand joins the zeros to the ID, so every value reaches the same length.
The ID 4127 padded to width 8 becomes 00004127.
The example
Three worked examples. Change any yellow input in the practice workbook and the results recalculate.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Case | ID | Width | Padded | Length |
| 2 | ID 1 | 4127 | 8 | 00004127 | 8 |
| 3 | ID 2 | 92 | 6 | 000092 | 6 |
| 4 | ID 3 | 350018 | 8 | 00350018 | 8 |
The formula
Here is the formula, built directly from the inputs:
How it works
Here is the logic, one piece at a time:
LEN(B2)counts the existing characters.C2-LEN(B2)is the missing digits.REPT("0",...)builds the zeros.&B2appends the ID.
Keep every number in its own input cell so the formula never needs editing.
Try it: interactive demo
Enter the values below.
Variations
Using TEXT
Fixed width of 8.
Trim spaces first
Clean stray spaces.
Pitfalls & errors
If the ID is longer than the width, REPT gets a negative count and returns #VALUE!.
Keep IDs as text so zeros are not stripped again.
Wrap in IFERROR for mixed-length data.
Practice workbook
Frequently asked questions
Why not TEXT?
Does it work on letters?
Stop fighting formulas. Learn them in a day.
This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.
See the Formulas & Functions Class