How to pad text with spaces to a fixed length in Excel
Formula (Excel and Google Sheets)
=LEFT(A2&REPT(" ",$E$1),$E$1)Add plenty of spaces and cut back to the width: =LEFT(A2&REPT(" ",12),12) makes every value exactly 12 characters.
- Result on the example
- one result per row in
B2, filled down toB6 - Works in
- Every current version
- Google Sheets
- Same formula
See it work
The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.
How it works
REPT adds as many spaces as the width, so there are always enough, and LEFT keeps exactly the width. Short names get trailing spaces and long names are cut, which is what fixed-width files for banks and older systems expect.
=LEFT(A2&REPT(" ",$E$1),$E$1)In Google Sheets
The same formula works in Google Sheets: =LEFT(A2&REPT(" ",$E$1),$E$1). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =RIGHT(REPT(" ",$E$1)&A2,$E$1) | Aiko, Ben Adams, Chidi Okafor…Different result | Pads on the left instead, which right-aligns the text; the usual layout for amounts in fixed-width files. Spaces go in front: " Aiko". |
Common mistakes
- In a proportional font the padded values still look uneven. Check alignment in a fixed-width font like Courier New.
- TRIM, and many imports, strip the padding again. Pad as the last step before export.
- Names longer than the width are cut without warning. Flag them with
LEN(A2)>$E$1.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Pad text with spaces to a fixed length
B2, pad the name with spaces on the right so it is exactly as long as the width in E1, cutting longer names. Fill down to B6.Questions
How do I pad numbers with zeros instead?
Use TEXT: =TEXT(A2,"00000000").
How do I pad with dots, like a table of contents?
Repeat a dot instead: =LEFT(A2&REPT(".",30),30).
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.