Smart Systems for Home

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

Excel TRIM Function: Remove Extra Spaces from Text

· 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

The Excel TRIM function removes extra spaces between words and eliminates leading and trailing spaces, leaving only single spaces between words. It does not affect normal spacing within text and works on any text string stored in a cell. No add-ins or special tools are required—TRIM is a built-in function available in all modern versions of Excel.

What You'll Need

  • Microsoft Excel (2007 or later)
  • A worksheet containing text with unwanted spaces
  • Basic familiarity with entering formulas in Excel

Step-by-Step

  1. Open your Excel workbook and locate the column or cell containing text with extra spaces—this could be names, addresses, product codes, or imported data.
  2. Click on an empty cell next to the first text entry (for example, if your data is in column A, select cell B1).
  3. Type the formula: =TRIM(A1), replacing A1 with the actual reference to the cell containing the text you want to clean. Make sure the cell reference matches the row of your data.
  4. Press Enter. The result will show the same text but with all leading, trailing, and extra internal spaces reduced to single spaces.
  5. Hover over the bottom-right corner of the cell with the formula until the cursor turns into a small black cross (the fill handle).
  6. Click and drag the fill handle down over all the rows that contain text you want to trim. Excel will automatically adjust the cell reference (A2, A3, A4, etc.) for each row.
  7. Once all rows are filled, select the entire column of trimmed results (e.g., column B), right-click, and choose Copy.
  8. Select the original column (e.g., column A), right-click, and choose Paste Values (not Paste Formula). This replaces the original text with the cleaned version without keeping the formula.
  9. Delete the helper column (column B) if you no longer need it, to keep your sheet clean.

Common Mistakes

  • Using TRIM on numeric values—TRIM only works on text. If a number appears to have spaces, it may be stored as text; convert it to a number with VALUE() first if needed.
  • Forgetting to paste values after using the formula. If you leave the formula in place, the original data remains unchanged and can cause confusion later.
  • Assuming TRIM removes non-breaking spaces (ASCII 160). TRIM only removes standard spaces (ASCII 32). Non-breaking spaces from web content or copied text will remain and require additional cleaning.
  • Applying TRIM to blank cells—while harmless, it may create unnecessary formulas. Use IF to skip blanks: =IF(A1="","",TRIM(A1))
  • Using TRIM on cells with line breaks. TRIM does not remove line breaks (CHAR(10) or CHAR(13)). You must use SUBSTITUTE before TRIM to handle them.

Tips

  • To clean non-breaking spaces along with regular spaces, combine TRIM with SUBSTITUTE: =TRIM(SUBSTITUTE(A1,CHAR(160)," ")). This replaces non-breaking spaces with regular ones, then trims.
  • For data imported from websites or PDFs, always use =TRIM(SUBSTITUTE(SUBSTITUTE(A1,CHAR(10),""),CHAR(13),"")) to remove line breaks before trimming.
  • Use the Formula Auditing tool (Formulas > Evaluate Formula) to step through how TRIM processes complex strings if results seem unexpected.
  • When working with large datasets, consider using Power Query (Data > Get & Transform) for batch text cleaning—it’s faster and preserves original data better.
  • Always make a backup copy of your data before mass-editing. TRIM is irreversible if you overwrite original cells without keeping the formula.

Troubleshooting

If TRIM doesn’t seem to work, follow these steps:

  1. Check if the cell contains actual text. If the cell displays a number but has spaces, it may be formatted as text. Use =ISTEXT(A1) to confirm—it should return TRUE.
  2. Verify that the spaces are standard spaces. Type =CODE(LEFT(A1,1)) to check the ASCII code of the first character. If it returns 160 instead of 32, you’re dealing with a non-breaking space.
  3. If TRIM leaves double spaces after cleaning, the source text likely contains tabs (CHAR(9)) or other non-space characters. Use =TRIM(SUBSTITUTE(SUBSTITUTE(A1,CHAR(9)," "),CHAR(160)," ")) to handle tabs and non-breaking spaces together.
  4. If the formula returns a #NAME? error, Excel doesn’t recognize TRIM. This usually means your Excel language version uses a different name, like STRECKEN in German or GAFFER in French. Look up your language’s equivalent function.
  5. If dragging the fill handle doesn’t work, ensure you’re not in Edit mode. Click out of the formula cell and try again. Also check that the cells below aren’t merged.
  6. If pasting values doesn’t work, ensure you’re using Paste Values under Paste Options (the icon with 123), not just Ctrl+V. Some versions require right-click > Paste Values.

Frequently Asked Questions

Does TRIM remove all spaces from a cell?

No. TRIM only removes leading, trailing, and extra internal spaces—leaving exactly one space between words. It preserves single spaces between words intentionally.

Can TRIM fix numbers with spaces in them?

No. TRIM only works on text. If a number appears as " 123 " with spaces, it’s stored as text. Use =VALUE(TRIM(A1)) to convert it to a true number after trimming.

Why does my data still have extra spaces after using TRIM?

Most likely, you’re seeing non-breaking spaces (ASCII 160) from web content or copied text. Use =TRIM(SUBSTITUTE(A1,CHAR(160)," ")) to fix this.

Does TRIM work in Excel Online?

Yes. TRIM works the same in Excel for the web as in desktop Excel. All standard functions are supported in the online version.

Can I use TRIM to clean an entire column at once without formulas?

Not directly. TRIM requires a formula. But you can use Find & Replace to remove double spaces manually: press Ctrl+H, enter two spaces in Find, one space in Replace, and click Replace All. Repeat until no more replacements occur. This doesn’t remove leading/trailing spaces, so TRIM is still better.

Is TRIM case-sensitive?

No. TRIM only affects spaces, not letter case. It won’t change uppercase to lowercase or vice versa. Use LOWER() or UPPER() if you need to adjust case separately.