How to Trim Blank Space in Excel: Step-by-Step Guide
In this article
To trim blank space in Excel, you can use the TRIM function to remove leading, trailing, and multiple internal spaces from text, or use Find & Replace to remove spaces globally. For non-breaking spaces (common when pasting from web pages), TRIM alone won't work—you'll need SUBSTITUTE with CHAR(160) or a combination of both. The method you choose depends on whether you want to clean up a few cells or an entire column, and whether the spaces are regular spaces or special characters.
What You'll Need
- Microsoft Excel (any recent version for Windows, Mac, or the web)
- Your data open in a worksheet
- Basic familiarity with entering formulas and using the ribbon
Step-by-Step
- Identify the type of blank space. Click a cell that appears to have extra spaces and look at the formula bar. If you see normal spaces between words or at the start/end, TRIM will handle them. If the spaces look unusually wide or the text was pasted from a website, they may be non-breaking spaces (character code 160), which TRIM ignores. You can check by using
=CODE(MID(A1,1,1))in a blank cell—if it returns 160, you have a non-breaking space. - For regular spaces, use the TRIM function. In an empty column next to your data (say column B if your data is in A), enter
=TRIM(A1)in cell B1. This removes leading and trailing spaces and reduces multiple internal spaces to a single space. Press Enter. - Copy the formula down. Drag the fill handle (the small square at the bottom-right of cell B1) down to apply the formula to all rows you need to clean. Alternatively, double-click the fill handle to auto-fill down to the last row of adjacent data.
- Replace the original data with the cleaned values. Select the new column with the TRIM results, copy it (Ctrl+C or Command+C), then right-click the original column and choose Paste Special > Values. This overwrites the original text with the trimmed version. Delete the helper column afterward.
- For non-breaking spaces, combine SUBSTITUTE and TRIM. In a blank cell, enter
=TRIM(SUBSTITUTE(A1,CHAR(160)," ")). This replaces all non-breaking spaces with regular spaces, then TRIM removes the extra ones. Copy down and paste as values as above. - Use Find & Replace for a quick global cleanup. Select the range or column you want to clean. Press Ctrl+H (Windows) or Command+H (Mac) to open Find & Replace. In the Find what box, type a single space. Leave Replace with blank, then click Replace All. This removes every space, including those between words—so use it only when you want to delete all spaces, not just extra ones. For non-breaking spaces, you can copy one from the cell and paste it into the Find what box, then replace with nothing.
- Use Power Query for large or recurring tasks. If you clean the same type of data regularly, select your data and go to Data > From Table/Range. In Power Query Editor, right-click the column header, choose Transform > Trim, and also Transform > Clean to remove non-printable characters. Then click Close & Load to output a clean table. This method is repeatable and doesn't alter your original data.
- Check your results. After cleaning, use
=LEN(A1)before and after to confirm spaces were removed. You can also visually inspect a few cells. If some spaces remain, they may be other whitespace characters like CHAR(9) (tab) or CHAR(10) (line break); use SUBSTITUTE to replace those with a space before applying TRIM.
Common Mistakes
- Using TRIM on non-breaking spaces. TRIM only removes regular spaces (character 32). If your data came from a web page or another system, it may contain CHAR(160), which TRIM leaves untouched. Always test with CODE or use SUBSTITUTE first.
- Replacing all spaces with nothing. Find & Replace with a space in the Find box and nothing in Replace will delete every space, merging words together (e.g., "New York" becomes "NewYork"). Use TRIM instead when you want to keep single spaces between words.
- Forgetting to paste as values. If you copy the TRIM formula and paste it normally over the original data, you'll overwrite the original text with formulas that reference the now-overwritten cells, causing circular references or errors. Always use Paste Special > Values.
- Not accounting for line breaks. Cells with Alt+Enter line breaks contain CHAR(10), which TRIM does not remove. Use SUBSTITUTE(A1,CHAR(10)," ") before TRIM if you need to flatten the text.
- Applying TRIM to numbers. TRIM returns text, so if your cells contain numbers stored as text, TRIM will keep them as text. Convert back to numbers with Value or by multiplying by 1 if needed.
Tips
- Work on a copy of your data or use a helper column so you can compare before and after.
- Use
=TRIM(CLEAN(A1))to remove both extra spaces and non-printable characters in one go. CLEAN removes characters like tabs and line breaks, but not non-breaking spaces. - For a quick visual check, turn on Formula View (Ctrl+`) to see all formulas, or use conditional formatting to highlight cells with leading/trailing spaces (e.g., a formula like
=A1<>TRIM(A1)). - If you need to remove spaces only from the start or end but keep internal spacing as-is, use
=TRIM(A1)still works because it collapses internal multiple spaces to one—but if you want to preserve multiple internal spaces, use=SUBSTITUTE(A1," ","")only for leading/trailing? Actually, there's no built-in function for that; you can use a combination of FIND and MID, but TRIM is usually sufficient. - When pasting data from the web, paste as plain text (Paste Special > Text) to avoid bringing in non-breaking spaces and other formatting.
Troubleshooting
- TRIM doesn't seem to work. Check if the spaces are non-breaking (CHAR(160)). Use
=CODE(MID(A1,1,1))on a cell that starts with a space; if it returns 160, use SUBSTITUTE as described. - Some spaces remain after TRIM. They might be other whitespace characters like CHAR(9) (tab) or CHAR(13) (carriage return). Use
=TRIM(SUBSTITUTE(SUBSTITUTE(A1,CHAR(9)," "),CHAR(13)," "))to replace them with spaces first. - Formulas show #VALUE! errors. This can happen if the cell contains an error value or if you're referencing a cell with a formula that returns an error. Check the source cell.
- Data looks clean but sorting/filtering still treats entries as different. There may be trailing spaces that are hard to see. Use LEN to compare lengths, or apply TRIM again.
- You accidentally deleted all spaces. If you used Find & Replace to remove all spaces, you can't undo after saving. Restore from a backup or re-enter the data. Always work on a copy.
Frequently Asked Questions
Can I trim blank space without using formulas?
Yes, you can use Find & Replace to remove all spaces, but that deletes spaces between words too. For selective trimming, formulas are the most precise method. Power Query also offers a no-formula approach for recurring tasks.
Does TRIM remove spaces between words?
TRIM removes leading and trailing spaces and reduces multiple internal spaces to a single space. It does not remove single spaces between words, which is usually what you want.
Why doesn't TRIM remove all spaces in my data?
TRIM only handles regular spaces (character 32). If your data contains non-breaking spaces (character 160), tabs, or line breaks, you need to use SUBSTITUTE or CLEAN in combination with TRIM.
Can I trim spaces in multiple columns at once?
Yes, you can apply the TRIM formula to each column separately, or use Power Query to transform multiple columns in one step. There's no built-in multi-column trim, but you can copy the formula across columns.
Will trimming spaces affect my numbers or dates?
TRIM returns text, so if you apply it to numbers or dates, they will become text. You can convert them back to numbers using Value or by multiplying by 1. Dates may need special handling.
Is there a way to trim spaces automatically as I type?
Excel doesn't have a built-in auto-trim feature. You can use a worksheet change event with VBA, but that requires macros and is not recommended for casual users. For most purposes, manual trimming with formulas or Power Query is sufficient.