How to Eliminate Spaces in Excel: Trim, Remove, Clean Guide
In this article
Excel eliminates extra spaces to clean data, prevent errors in formulas, and ensure accurate matching or imports. You can remove leading, trailing, and nonprinting characters using built-in functions like TRIM, CLEAN, or a combination of SUBSTITUTE and FIND. No add-ins or special tools are required.
What You'll Need
- Microsoft Excel (any modern version: Excel 2010, 2013, 2016, 2019, 2021, or Microsoft 365)
- A dataset with unwanted spaces (e.g., extra spaces between words, leading/trailing spaces, or nonbreaking spaces)
Step-by-Step
- Identify the type of space issue: First, determine whether your spaces are standard spaces (ASCII 32), nonbreaking spaces (often inserted by web imports, ASCII 160), or extra spaces between words. Use the
CODE(LEFT(A1))orCLEAN(A1)functions to inspect the first character. If it returns 160, you're dealing with nonbreaking spaces; if 32, it's a regular space. - Use TRIM for standard extra spaces: In a new blank column (e.g., Column B), enter
=TRIM(A1)and press Enter. TRIM removes leading and trailing spaces and reduces multiple spaces between words to a single space. Drag the fill handle down to apply it to the rest of your data range. - Handle nonbreaking spaces with SUBSTITUTE: If TRIM doesn’t fix all spaces (e.g., data imported from websites), combine SUBSTITUTE and TRIM:
=TRIM(SUBSTITUTE(A1,CHAR(160)," ")). This replaces nonbreaking spaces (CHAR(160)) with regular spaces, then TRIM cleans up duplicates and ends. - Remove all spaces entirely (if needed): To delete every space—including those between words—use
=SUBSTITUTE(A1," ",""). This yields "FirstNameLastName" from "First Name Last Name". Again, drag the formula down to apply it across your dataset. - Eliminate nonprinting characters with CLEAN: For data with hidden characters like line breaks or formatting codes, use
=CLEAN(A1). CLEAN removes all nonprintable characters (ASCII 0–31), but not spaces. For combined cleaning, use=TRIM(CLEAN(A1)), especially after copying data from PDFs, web pages, or databases. - Replace source data with formulas (optional): After verifying results, copy the cleaned column (e.g., B1:B100), right-click the original column (A), and choose Paste Special > Values to overwrite formulas with static text. This prevents accidental formula breakage and reduces file size.
Common Mistakes
- Assuming TRIM removes all spaces: TRIM only removes leading/trailing spaces and reduces internal multiple spaces to one. It does not eliminate spaces between words if they’re single spaces.
- Overlooking nonbreaking spaces: Spaces copied from web pages or PDFs are often ASCII 160 (nonbreaking), invisible in Excel. TRIM alone won’t remove them—SUBSTITUTE with CHAR(160) is required.
- Skipping paste-as-values: Leaving formulas in place means future edits to the original column (A) may break references or cause inconsistencies. Always paste values after finalizing the cleaned column.
- Applying TRIM to numeric data: TRIM only works on text. If numbers are formatted as text (e.g., "123 " with trailing space), TRIM cleans them but they remain text. Convert to numbers afterward using
=VALUE(TRIM(A1))or the Text to Columns feature.
Tips
- Use a helper column: Always clean data in a new column first. This lets you compare original vs. cleaned side-by-side and revert if needed.
- Batch-clean with Flash Fill: Type the cleaned result in the first cell of a new column (e.g., B1), then press Ctrl+E to trigger Flash Fill. Excel may auto-complete the rest if patterns are clear—works well for removing all spaces or trimming ends.
- Check for hidden line breaks: If text wraps oddly or seems misaligned, use
=LEN(A1)vs.=LEN(TRIM(A1)). A large difference suggests line breaks (CHAR(10) or CHAR(13)). Use=TRIM(SUBSTITUTE(SUBSTITUTE(A1,CHAR(10),""),CHAR(13),""))to remove them. - Preserve leading zeros: If cleaning ZIP codes or IDs like "01234", convert to text first (format as Text or prefix with an apostrophe
'), then apply cleaning formulas. Excel may drop leading zeros otherwise. - Test with a small range: Before cleaning thousands of rows, test on 5–10 rows to confirm the formula behaves as expected.
Troubleshooting
If your cleaning steps don’t work, follow this checklist:
- Verify the space type: In a blank cell, type
=CODE(MID(A1,2,1))to check the second character (or use=CODE(LEFT(A1))and=CODE(RIGHT(A1))). If it returns 160 (not 32), use SUBSTITUTE with CHAR(160). - Check for non-breaking hyphens or other characters: Some systems insert special characters like em dashes or thin spaces. Use
=CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))in an array formula (Ctrl+Shift+Enter in older Excel) to list all character codes, or use the Find & Select > Find tool with^pfor line breaks. - Ensure no merged cells: Merged cells can disrupt drag-and-fill. Unmerge the range (Home > Align > Merge & Center > Unmerge Cells) before reapplying formulas.
- Confirm cell formatting: If cells are formatted as Number or General, Excel may auto-convert cleaned text to numbers. Right-click > Format Cells > Text before pasting values.
- Try Power Query for large datasets: Go to Data > Get Data > From Other Sources > From Microsoft Query (or From Table/Range in newer Excel). In Power Query Editor, right-click a column > Transform > Trim or use
Text.CleanandText.Replacesteps. Click Close & Load to return cleaned data.
Frequently Asked Questions
Does TRIM remove spaces between words?
No—TRIM only reduces multiple spaces between words to a single space and removes leading/trailing spaces. It preserves one space between words (e.g., "Hello World" becomes "Hello World"). To remove all spaces, use =SUBSTITUTE(A1," ","").
Why does TRIM leave spaces after I use it?
Nonbreaking spaces (CHAR(160)) are invisible but not removed by TRIM. Replace them first with =SUBSTITUTE(A1,CHAR(160)," "), then apply TRIM. Also, check for line breaks using =ISNUMBER(FIND(CHAR(10),A1))—remove them with =SUBSTITUTE(A1,CHAR(10),"").
Can I remove spaces without using formulas?
Yes. Select your range, press Ctrl+H, type a space in Find what and leave Replace with blank, then click Replace All. Note: This removes all spaces—including between words—and is irreversible without undo (Ctrl+Z). Use carefully.
Will cleaning text affect my pivot tables or VLOOKUPs?
Yes—if the original data has extra spaces, VLOOKUPs or pivot groupings may fail. After cleaning, refresh all pivot tables (Right-click pivot > Refresh) and retest VLOOKUP/INDEX-MATCH formulas. Consistent data formatting prevents #N/A errors.
How do I clean spaces in numbers stored as text?
First clean the text with =TRIM(SUBSTITUTE(A1,CHAR(160)," ")), then convert to number with =VALUE(B1) (where B1 holds the cleaned text). Alternatively, use Data > Text to Columns > Delimited > Next > Next > Finish, choosing General format—this often auto-converts text numbers.
Is there a keyboard shortcut to trim spaces?
No single shortcut, but combine Ctrl+H (Find & Replace) for quick global space removal, or use Alt+H+O+I+T to open Format Cells > Text to preserve formatting before pasting values. For formulas, type =TRIM(A1) manually or use AutoFill.