Home
How to Remove Extra or All Spaces in Excel Fast
Unwanted spaces are the silent killers of Excel productivity. They cause VLOOKUP formulas to return errors, pivot tables to categorize the same item into two different rows, and SUM functions to result in zero. Whether you are dealing with leading spaces, trailing spaces, or stubborn non-breaking spaces from a web export, cleaning your data is the first step toward accurate analysis.
To quickly remove spaces in Excel, use the TRIM function for extra spaces (=TRIM(A1)) or the Find and Replace tool (Ctrl + H) to delete all spaces entirely.
Below is a detailed breakdown of every method available, ranging from simple shortcuts to advanced data transformation techniques.
Why Spaces Cause Problems in Excel
Before diving into the "how," it is essential to understand why these invisible characters are so disruptive. In Excel, a space is a character with its own ASCII code (usually Code 32). To the human eye, "Apple" and "Apple " look identical. However, to Excel's logic engine:
"Apple" = "Apple "is FALSE.- A VLOOKUP searching for "Apple" will fail if the source data contains "Apple ".
- Numbers formatted as text with a trailing space cannot be used in mathematical calculations.
Cleaning these spaces ensures data integrity and saves hours of troubleshooting broken formulas.
Method 1: Use the TRIM Function for Extra Spaces
The TRIM function is the most common tool for data cleaning. It is designed to remove leading and trailing spaces while collapsing multiple consecutive spaces between words into a single space.
How the TRIM Formula Works
The syntax is simple:
=TRIM(text)
If cell A1 contains " Data Cleaning Is Fun ", the formula =TRIM(A1) will return "Data Cleaning Is Fun".
Step-by-Step Implementation
- Insert a Helper Column: Create a new column next to the data you want to clean.
- Enter the Formula: In the first cell of the helper column, type
=TRIM(A2)(assuming A2 is your first data point). - Drag the Fill Handle: Double-click or drag the bottom-right corner of the cell down to apply the formula to the entire range.
- Convert to Values: Because the results are formulas, you must finalize them. Copy the helper column, right-click the original column, and select Paste Special > Values.
- Delete the Helper Column: You can now safely remove the temporary column.
Best Use Cases for TRIM
- Cleaning names (e.g., " John Doe " becomes "John Doe").
- Removing accidental spaces at the end of product descriptions.
- Preparing data for a VLOOKUP or XLOOKUP.
Method 2: Use Find and Replace to Delete All Spaces
Sometimes, you don't want to just "tidy" the spaces; you want them gone entirely. This is common when dealing with account numbers, phone numbers, or SKU codes where spaces are purely formatting errors.
The Shortcut Method
- Select the Range: Highlight the cells you wish to clean.
- Open Find and Replace: Press
Ctrl + Hon your keyboard. - Define the Search:
- In the Find what box, press your Space bar once.
- Leave the Replace with box completely empty.
- Execute: Click Replace All.
Why This Method is Powerful
In my experience, this is the fastest way to handle large datasets (over 50,000 rows) without taxing Excel's processing power with formulas. However, use it with caution. If you apply this to a column of full names, "Sarah Jane Smith" will become "SarahJaneSmith".
Method 3: Use the SUBSTITUTE Function for Formulaic Control
If you need a formula-based approach to remove every space, SUBSTITUTE is the professional's choice. Unlike TRIM, which leaves one space between words, SUBSTITUTE replaces every instance of a space with nothing.
The SUBSTITUTE Syntax
=SUBSTITUTE(text, old_text, new_text, [instance_num])
To remove all spaces in cell A1:
=SUBSTITUTE(A1, " ", "")
Advanced Application: Removing Specific Spaces
One unique feature of SUBSTITUTE is the instance_num argument. If a cell contains "100 200 300" and you only want to remove the first space, you could use:
=SUBSTITUTE(A1, " ", "", 1)
Result: "100200 300"
This level of granular control is something the standard Find and Replace tool cannot offer.
Method 4: Handling Stubborn "Invisible" Spaces (Web Data)
Have you ever used TRIM and found that the spaces didn't disappear? This is a common frustration when copying data from websites or ERP systems like SAP and Oracle.
The Non-Breaking Space (CHAR 160)
Webpages often use a "Non-Breaking Space" ( ). In Excel, this is represented by CHAR(160). The standard TRIM function only recognizes CHAR(32) (the regular space).
The Ultimate Cleaning Formula
To remove both regular spaces and non-breaking spaces, you need to "nest" your functions. In our tests, this is the most robust way to clean imported data:
=TRIM(SUBSTITUTE(A1, CHAR(160), " "))
This formula tells Excel: "Find every non-breaking space, turn it into a regular space, and then use the TRIM function to clean up everything."
Adding the CLEAN Function
If your data also contains weird line breaks or non-printable symbols (often represented by little squares), add the CLEAN function:
=TRIM(CLEAN(SUBSTITUTE(A1, CHAR(160), " ")))
Method 5: Using Flash Fill for Visual Cleaning
If you are not a fan of formulas, Flash Fill is a "magic" feature introduced in Excel 2013 that uses pattern recognition.
How to Use Flash Fill
- Suppose column A has " 123 456 ".
- In column B, manually type the desired result: "123456".
- Move to the next cell down (B2) and press
Ctrl + E. - Excel will look at your manual entry, recognize you are removing spaces, and automatically fill the rest of the column.
Pro Tip: Flash Fill is excellent for small to medium datasets, but always double-check the results at the bottom of the list. If the pattern changes slightly halfway down, Flash Fill might guess incorrectly.
Method 6: Power Query for Bulk Data Transformation
For professionals handling recurring reports with thousands of rows, manual cleaning is inefficient. Power Query (Get & Transform) is the superior tool for this task.
Steps to Clean Spaces in Power Query
- Select Data: Go to the Data tab and select From Table/Range.
- Open Editor: The Power Query Editor window will open.
- Select Column: Right-click the header of the column you want to clean.
- Transform:
- Select Transform > Trim to remove leading and trailing spaces.
- Select Transform > Clean to remove non-printable characters.
- Replace Values: If you need to remove all spaces, right-click, select Replace Values, type a space in "Value to Find," and leave "Replace With" blank.
- Load: Click File > Close & Load to return the cleaned data to Excel.
The best part? If you update the source data next week, you simply click Refresh, and Power Query performs all these cleaning steps again instantly.
Troubleshooting: Why is My Formula Still Not Working?
If you have applied TRIM and SUBSTITUTE and your VLOOKUP still fails, check for these three common issues:
1. Hidden Characters Other Than Spaces
Sometimes data contains CHAR(9) (Tabs) or CHAR(13) (Carriage Returns). You can identify the character code of a stubborn space by using the formula:
=CODE(RIGHT(A1, 1))
This will tell you the ASCII code of the last character in the cell. If it returns 160, use the CHAR(160) method mentioned above.
2. Number vs. Text Formatting
Removing spaces from a number often leaves it formatted as "Text." You can tell this is happening if the number is aligned to the left of the cell. To fix this, multiply the result by 1:
=TRIM(A1)*1
This forces Excel to recognize the cleaned string as a numeric value.
3. Calculation Options
Ensure your Workbook is set to Automatic Calculation (Formulas tab > Calculation Options). If it is set to Manual, your TRIM formula won't update until you press F9.
Comparison of Methods
| Method | Best For | Removes All Spaces? | Removes Extra Spaces? | Complexity |
|---|---|---|---|---|
| TRIM | Standard text cleaning | No | Yes | Low |
| Find & Replace | One-time bulk removal | Yes | Yes | Low |
| SUBSTITUTE | Fixed ID cleaning | Yes | Yes | Medium |
| Power Query | Recurring large reports | Yes | Yes | High |
| Flash Fill | Quick visual fixes | Depends on user | Yes | Low |
Summary and Key Takeaways
Cleaning spaces is a fundamental skill for anyone working in Excel.
- Use TRIM for general text where you want to keep single spaces between words.
- Use Find and Replace or SUBSTITUTE when you need to remove every single space.
- Combine TRIM, CLEAN, and SUBSTITUTE(CHAR(160)) for data imported from the web.
- Leverage Power Query to automate these steps for recurring work.
By implementing these methods, you will eliminate the most common source of data errors and ensure your spreadsheets remain professional and functional.
FAQ: Frequently Asked Questions about Excel Spaces
What is the shortcut to remove spaces in Excel?
The fastest shortcut is Ctrl + H. Enter a space in the "Find what" field and leave the "Replace with" field empty, then click "Replace All." This removes every space in the selected range.
Does TRIM remove all spaces?
No, TRIM only removes spaces at the beginning (leading) and end (trailing) of a text string, and reduces multiple spaces between words to a single space. It does not remove the spaces between words entirely.
How do I remove spaces in Excel without a formula?
You can use the Find and Replace tool (Ctrl + H) or Flash Fill (Ctrl + E). Both methods allow you to clean data without writing a single line of code.
Why won't TRIM remove the spaces in my data?
This usually happens because the "spaces" are actually non-breaking spaces (CHAR 160) commonly found in HTML/web data. To fix this, use =TRIM(SUBSTITUTE(A1, CHAR(160), " ")).
How can I remove spaces before a number in Excel?
You can use =TRIM(A1) if the number is stored as text. To ensure it converts back to a number, use =VALUE(TRIM(A1)).
-
Topic: how do i remove extra space from a cell - Microsoft Q& Ahttps://learn.microsoft.com/en-gb/answers/questions/5427301/how-do-i-remove-extra-space-from-a-cell
-
Topic: How to Remove Spaces in Excel: 5 Good Methods | DataCamphttps://www.datacamp.com/nl/tutorial/how-to-remove-spaces-in-excel
-
Topic: How to Remove Whitespace in Excel [Step-by-Step Guide]https://www.wps.com/blog/how-to-remove-whitespace-in-excel-step-by-step/