# How to remove all spaces from a cell in Excel

Replace every space with nothing: =SUBSTITUTE(A2," ",""). Unlike TRIM, it also removes the spaces between words.

**Excel:** `=SUBSTITUTE(A2," ","")` (Every current version)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B |
| --- | --- |
| Code (with spaces) | No spaces |
| GB29 NWBK 6016 1331 9268 19 |  |
| DE89 3704 0044 0532 0130 00 |  |
| SW1A 1AA |  |
| 55401 |  |
| A 12 B 34 |  |

Formula in B2, filled to B6: `=SUBSTITUTE(A2," ","")`

Result: GB29NWBK60161331926819; DE89370400440532013000; SW1A1AA; 55401; A12B34

## 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.

## Other ways

- `=SUBSTITUTE(SUBSTITUTE(A2," ",""),CHAR(160),"")`: 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.

## 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.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/remove-all-spaces-from-a-cell
