Yes, you can get rid of spaces in Excel, and the method depends on the type of space: leading/trailing spaces (before or after text), extra spaces between words, or non-breaking spaces that paste in from web pages. The quickest fix for most cases is the TRIM function, which removes all spaces except single spaces between words. For all spaces, including those between words, use SUBSTITUTE or Find & Replace. Below are step-by-step methods for each scenario, plus how to convert formulas to permanent values.
What You'll Need
- A computer with Microsoft Excel (2013 or later, or Microsoft 365). The steps also work in Google Sheets, with slight menu differences.
- Your spreadsheet open, with the column containing spaces selected or identified.
- Basic familiarity with entering formulas in a cell (typing
=and pressing Enter).
Step-by-Step
Method 1: Remove Leading/Trailing/Extra Spaces with TRIM
- Identify the data range. For example, if your data is in cells A1:A50, you'll create a helper column to hold the cleaned text.
- Insert a new column next to your data. Click on the letter at the top of column B (or any empty column) to select it, right-click, and choose "Insert." This shifts your data right, giving you a clean column for formulas.
- Enter the TRIM formula. In the first cell of the new column (e.g., B1), type:
=TRIM(A1)and press Enter. This removes all spaces at the beginning and end of the text, and collapses multiple spaces between words to a single space. - Copy the formula down. Click on the cell with the formula, then double-click the small square at the bottom-right corner of the cell (the fill handle). Excel fills the formula down the entire column, cleaning every row.
- Check the results. Scan the new column to ensure the text looks correct. If you see any remaining spaces, they might be non-breaking spaces (see Method 3).
- Replace the original data with the cleaned values. Select the entire new column (click the column letter), press
Ctrl+Cto copy, then right-click on the first cell of your original data (e.g., A1) and choose "Paste Special" > "Values." This overwrites the original text with the cleaned text, without leaving formulas behind. - Delete the helper column. Click the letter of the helper column, right-click, and choose "Delete." Your data is now clean.
Method 2: Remove ALL Spaces (Including Between Words) with SUBSTITUTE
- Decide if you really want to remove all spaces. This is useful for codes, phone numbers, or IDs where spaces are not needed (e.g., "AB 123" becomes "AB123"). If you need to keep single spaces between words, use Method 1 instead.
- In a new column, enter the SUBSTITUTE formula. Type:
=SUBSTITUTE(A1," ","")and press Enter. The formula replaces every space character with nothing (empty text). - Copy down and paste as values exactly as described in Steps 4–7 of Method 1. This method removes every space, including those between words, so "John Doe" becomes "JohnDoe".
Method 3: Remove Non-Breaking Spaces (CHAR 160)
Non-breaking spaces often come from pasting text from websites or Word documents. They look like spaces but are a different character (code 160), so TRIM and SUBSTITUTE with a regular space won't remove them. To handle them:
- Use SUBSTITUTE with CHAR(160). In a new column, enter:
=SUBSTITUTE(A1,CHAR(160),"")to remove non-breaking spaces. You can also nest it with TRIM:=TRIM(SUBSTITUTE(A1,CHAR(160)," "))– this first converts non-breaking spaces to regular spaces, then trims extra ones. - If you have both types of spaces, combine both SUBSTITUTE calls:
=TRIM(SUBSTITUTE(SUBSTITUTE(A1,CHAR(160)," ")," "," "))– but that's complex. Simpler: run Method 1 first, then apply this method on the result. - Paste as values and delete the helper column as before.
Method 4: Find & Replace for Quick, One-Time Removal
- Select the range where you want to remove spaces. If you want the whole sheet, click the triangle at the intersection of row numbers and column letters (top-left corner).
- Open Find & Replace. Press
Ctrl+H(Windows) orCmd+Shift+H(Mac). - In "Find what," type a single space (press the spacebar once).
- Leave "Replace with" empty if you want to remove all spaces. If you want to remove only leading/trailing spaces, this method is not precise – it will remove all spaces, so use TRIM instead.
- Click "Replace All." Excel will tell you how many replacements it made. Click OK.
- Undo if it goes wrong. If you accidentally removed spaces you needed (like between words), press
Ctrl+Zimmediately to undo.
Common Mistakes
- Using TRIM and expecting it to remove all spaces. TRIM leaves single spaces between words by design. If you need no spaces at all, use SUBSTITUTE.
- Forgetting to paste as values. If you delete the helper column without pasting as values, your original data remains unchanged, or you end up with formulas that break when the helper column is gone.
- Replacing spaces with Find & Replace without checking for non-breaking spaces. If the spaces persist after Find & Replace, they are likely CHAR(160), which the normal spacebar character doesn't match.
- Applying TRIM to numbers stored as text. TRIM works on text, but if your data is a number with a space (like "1 234"), Excel may treat it as text. TRIM will still work, but the result will be text, not a number. Convert to number if needed.
Tips
- Use the TRIM function in Power Query for large datasets. If you have thousands of rows, you can load your data into Power Query (Data > From Table/Range), select the column, and use Transform > Format > Trim. This is faster and doesn't require helper columns.
- Check for spaces with the LEN function. Compare
=LEN(A1)with=LEN(TRIM(A1))to see how many spaces were removed. This helps verify the cleanup. - Use the CLEAN function to remove other non-printable characters. If you paste from web pages, you might have line breaks or tabs (CHAR 10, 13).
=CLEAN(TRIM(A1))removes those too. - For a one-off cleanup, use the "Trim Spaces" feature in Excel's Text to Columns. Select your data, go to Data > Text to Columns > Delimited > Next, then in the "Delimiters" section, uncheck all boxes, and click Finish. This sometimes trims leading/trailing spaces, but it's not reliable for all cases.
Troubleshooting
If TRIM doesn't remove the spaces: The spaces are likely non-breaking (CHAR 160). Use Method 3. You can verify by typing =CODE(MID(A1,2,1)) in a cell to see the character code of the second character – if it's 160, it's a non-breaking space.
If Find & Replace removes too much: You pressed Replace All without selecting the correct range, or you wanted to keep single spaces. Immediately press Ctrl+Z to undo, then use TRIM instead.
If the formula returns #VALUE!: Your data might contain a mix of text and numbers, or there are special characters. Check if the cell contains an error by looking at the data. If it's a number, TRIM should still work, but if you have a formula that returns an error, fix that first.
If the helper column shows formulas instead of values: You copied the column but pasted as formulas, not values. Select the helper column, copy, then Paste Special > Values.
If you have spaces in multiple columns: Repeat the process for each column, or use Power Query to clean all columns at once.
Frequently Asked Questions
Why does TRIM not remove all spaces in Excel?
TRIM is designed to remove leading, trailing, and extra spaces between words, but it keeps a single space between words. To remove every space, use SUBSTITUTE with a space as the old text and empty as the new text.
How do I remove spaces from a column without using a formula?
Use Find & Replace (Ctrl+H). Put a space in "Find what," leave "Replace with" empty, and click Replace All. This removes all spaces, but it will also remove spaces between words.
Can I remove spaces from numbers in Excel?
Yes. If the number is stored as text with spaces (e.g., "1 234"), use SUBSTITUTE to remove the spaces, then multiply by 1 to convert to a number, or use the VALUE function.
What is the difference between a regular space and a non-breaking space in Excel?
A regular space is character code 32. A non-breaking space is character code 160, often imported from web pages. TRIM and Find & Replace with a regular space won't remove non-breaking spaces; you need SUBSTITUTE with CHAR(160).
How do I remove spaces at the beginning and end of text only?
Use the TRIM function. It removes all leading and trailing spaces, and also collapses multiple spaces between words to a single space. If you want to keep multiple spaces between words, you'd need a more complex formula, but that's rare.
Will removing spaces affect my formulas or data validation?
If you have formulas that reference the cells, removing spaces may change the values, which could affect calculations. Data validation rules that rely on specific text may also break. Always check dependent formulas before cleaning data.