Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Clear Spaces in Excel: How to Remove Extra Whitespace

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To clear spaces in Excel, the fastest method for removing extra leading, trailing, or double spaces is the TRIM function. For removing all spaces (including single spaces between words), use the Find and Replace tool (Ctrl + H) and replace a space with nothing. These methods ensure your data is clean, consistent, and ready for accurate formulas or VLOOKUPs.

Cleaning whitespace is essential because Excel treats a cell containing "Apple " (with a trailing space) as a different value than "Apple". This often leads to errors in data analysis, failed searches, and broken formulas. Depending on whether you want to remove all spaces or just the unnecessary ones, you will use different tools.

What You'll Need

  • A computer with Microsoft Excel installed (Windows or macOS).
  • A dataset containing text with inconsistent spacing.
  • A blank helper column (if using the TRIM function).

Step-by-Step

Method 1: Using the TRIM Function (Removes Extra Spaces)

The TRIM function is designed to remove all leading and trailing spaces and reduce multiple spaces between words to a single space. Note that menu labels may differ slightly by version or region.

  1. Select a blank cell next to the data you want to clean.
  2. Type the formula =TRIM(A2), replacing "A2" with the cell reference of the text you want to clear.
  3. Press Enter to apply the formula.
  4. Click the fill handle (the small square at the bottom-right of the cell) and drag it down to apply the formula to the rest of the column.
  5. To replace the original messy data with the clean data:
    • Select the cells containing the TRIM formulas.
    • Copy them (Ctrl + C).
    • Right-click the original data cells and select Paste Special > Values (the icon with "123"). This removes the formula and keeps only the cleaned text.

Method 2: Using Find and Replace (Removes All Spaces)

Use this method if you need to remove every single space in a cell, such as when cleaning phone numbers or ID codes.

  1. Highlight the range of cells or the specific column you want to clear.
  2. Press Ctrl + H on your keyboard to open the Find and Replace dialog box.
  3. In the Find what: field, press the spacebar once.
  4. Leave the Replace with: field completely empty.
  5. Click Replace All.
  6. Excel will notify you how many replacements were made. Click OK and close the window.

Method 3: Using Power Query (For Large Datasets)

Power Query is a powerful tool for cleaning thousands of rows of data without writing complex formulas.

  1. Select your data range and go to the Data tab.
  2. Select From Table/Range. If prompted, confirm your data range and click OK.
  3. In the Power Query Editor window, right-click the header of the column you wish to clean.
  4. Navigate to Transform > Trim. This automatically removes leading and trailing whitespace from every cell in that column.
  5. Click Close & Load on the Home tab to return the cleaned data to a new Excel worksheet.

Common Mistakes

  • Overusing Find and Replace: Using Find and Replace to remove all spaces in a column of full names (e.g., "John Doe" becomes "JohnDoe"). Use TRIM instead for names.
  • Forgetting to Paste Values: After using the TRIM function, users often delete the original column before "Pasting as Values." This results in a #REF! error because the formula no longer has a source cell to reference.
  • Assuming TRIM removes all characters: TRIM only removes standard spaces. It does not remove non-breaking spaces (often found in data imported from websites) or tabs.

Tips

  • Combine with CLEAN: If your data contains non-printable characters (like line breaks), use =TRIM(CLEAN(A2)). The CLEAN function removes the non-printable characters, and TRIM handles the spaces.
  • Quick Selection: To select an entire column quickly before using Find and Replace, click the letter at the top of the column.
  • Verification: To check if a cell still has a hidden space, use the =LEN(A2) formula. If "Apple" shows a length of 6 instead of 5, there is a hidden space.

Troubleshooting

If TRIM or Find and Replace does not remove the spaces:

You are likely dealing with "non-breaking spaces" (HTML character 160), which are common in data copied from web browsers. Excel's standard TRIM and Find/Replace tools do not recognize these as standard spaces.

  1. Select a cell containing the stubborn space.
  2. In the formula bar, highlight and copy one of the invisible spaces.
  3. Press Ctrl + H to open Find and Replace.
  4. Paste that specific invisible character into the Find what: field.
  5. Leave Replace with: empty and click Replace All.

Frequently Asked Questions

Does TRIM remove spaces between words?

TRIM only removes leading and trailing spaces. If there are multiple spaces between words, it reduces them to a single space. It does not remove the single space separating words.

How do I remove only the first space in a cell?

Excel does not have a single-click button for this. You must use a formula like =REPLACE(A2, FIND(" ", A2), 1, ""), which finds the first space and replaces it with nothing.

Can I clear spaces automatically as I type?

No, Excel does not have a native "auto-trim" setting for data entry. You must clean the data after it has been entered or imported using the methods described above.

Is there a way to remove spaces using a keyboard shortcut?

While there is no "Clear Spaces" shortcut, Ctrl + H is the fastest way to access the Find and Replace menu to remove all spaces manually.

Will clearing spaces affect my Excel formulas?

If your formulas rely on exact text matches (like VLOOKUP or SUMIF), clearing spaces will often fix formulas that were previously failing due to hidden whitespace.