How to remove all spaces from a cell in Excel
Formula (Excel and Google Sheets)
=SUBSTITUTE(A2," ","")Replace every space with nothing: =SUBSTITUTE(A2," ",""). Unlike TRIM, it also removes the spaces between words.
- 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
SUBSTITUTE replaces each space with empty text, wherever it is. That's what you want for account numbers, IBANs and postcodes, where the spaces are only for readability. For names and sentences, use TRIM, which keeps single spaces between words.
=SUBSTITUTE(A2," ","")Result"GB29NWBK60161331926819"
A2"GB29 NWBK 6016 1331 9268 19"The value in A2.
SUBSTITUTE(A2," ","")"GB29NWBK60161331926819"SUBSTITUTE: Replaces matching text.- text
A2"GB29 NWBK 6016 1331 9268 19" - old_text
" " - new_text
""
- text
In Google Sheets
The same formula works in Google Sheets: =SUBSTITUTE(A2," ",""). 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 |
|---|---|---|
| =SUBSTITUTE(SUBSTITUTE(A2," ",""),CHAR(160),"") | GB29NWBK60161331926819, DE89370400440532013000, SW1A1AA… | Also removes non-breaking spaces from text copied from web pages. |
Common mistakes
- The result is text, even when it looks like a number ("55401"). Wrap it in VALUE if you need a number.
- Non-breaking spaces survive the plain version. Use the CHAR(160) alternative for web data.
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.
Remove all spaces from a cell
B2, remove every space from the code and fill down to B6.Questions
How do I remove only the extra spaces?
Use =TRIM(A2).
Can I do it without a formula?
Yes: Find and Replace, with a space in Find and nothing in Replace.
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.