Smart Systems for Home

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

How to Remove Whitespace in Excel (Step by Step)

· 7 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

Excel actually has several kinds of whitespace, and the right tool depends on which one you have. If the extra spaces live inside a single cell, the fastest fix is =TRIM(A2), which collapses every run of interior spaces to one and strips leading and trailing spaces. If you mean blank rows and columns scattered through your data, use the Go To Special dialog and delete whole rows or columns. If the gaps are non-breaking spaces pasted from a web page, TRIM will not touch them and you need SUBSTITUTE with CHAR(160) first. Work on a copy of the sheet, because most of these methods overwrite data.

What You'll Need

  • Excel on Windows, Mac, or Excel for the web. The built-in functions below work in all of them.
  • A backup copy of the workbook, especially if you plan to overwrite the original cells rather than use a helper column.
  • Roughly ten minutes, and a clear idea of whether you are cleaning text inside cells, removing blank rows, or both.
  • Optional but helpful: the Power Query editor, which is built into Excel, if your data comes in from an export or CSV every week.

Step-by-Step

  1. Identify the type of whitespace first. Click a suspect cell and look at the formula bar. Extra spaces before or after the text look like a gap at the start or end of the line. Extra spaces between words show as doubled gaps. A gap that TRIM later refuses to remove is usually a non-breaking space. Knowing which one you have saves you from applying the wrong fix twice.
  2. Test whether the problem is real. Turn on formula view with Ctrl+` (the backtick key, on the left of the 1 key) to see the raw contents, or use =LEN(A2) in an empty cell to count characters including spaces. Type the same text by hand into another empty cell with =LEN() and compare. A difference tells you how many stray characters you are dealing with.
  3. Create a helper column. Click the letter of the column after your data to select it, right-click, and choose Insert to add a blank column. Working in a helper column means you can inspect the result next to the original before committing.
  4. Apply TRIM. In the first empty cell of the helper column, type =TRIM(A2), replacing A2 with your first data cell. Press Enter, then drag the fill handle down, or double-click it to fill to the end of the adjacent data.
  5. Check a handful of results. Compare the trimmed column with the original on cells that had obvious problems and on any cell containing text you want preserved exactly, such as something inside quotation marks.
  6. Convert the formulas to values. Select the helper column, press Ctrl+C, then right-click the same range and choose Paste Special > Values. The formulas are replaced by plain text. Paste Special labels vary slightly between Excel versions and operating systems, but Values is present in every current one.
  7. Replace the original data. Copy the values column, right-click the original column, and use Paste Special > Values. Then delete the helper column. Your original cells are now text, not formulas, so any external references to that column still work.
  8. For stubborn non-breaking spaces, add SUBSTITUTE. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")), which turns each non-breaking space into an ordinary space and then trims. On Mac, you can also type a non-breaking space by holding Option and pressing the space bar, which is useful if you need to search for one manually with Find.
  9. To remove all spaces at once, use SUBSTITUTE or Find and Replace instead. =SUBSTITUTE(A2," ","") deletes every space, including the single ones between words, so it is only appropriate for postal codes, phone numbers, part numbers and similar strings where spaces carry no meaning. The same effect comes from selecting the range, pressing Ctrl+H, typing a space in Find what, leaving Replace with empty, and clicking Replace All. That last method cannot be undone with Ctrl+Z after you save, so keep your backup.
  10. For blank rows and columns, use Go To Special. Select the range you want to clean, press F5 (or Ctrl+G), click Special, choose Blanks, and click OK. Every blank cell in the range is selected. To delete entire blank rows, right-click a selected row header and choose Delete; for a selection of scattered cells, use the Delete dropdown on the Home tab and pick Delete Sheet Rows or Delete Sheet Columns.
  11. For recurring imports, use Power Query. With your data in a table, choose Data > From Table/Range, open Transform, and use Trim under the Format group to clean every selected text column at once. Also use Remove Rows > Remove Blank Rows if blanks come in from the source file. Close and Load, and the cleaning steps repeat whenever you refresh.
  12. Save a clean copy. Use Save As to keep the original version alongside the cleaned one until you have confirmed the results are correct.

Common Mistakes

Deleting the original too early. Overwriting the source column before checking the trimmed output leaves nothing to compare against if a formula strips something you needed. Always keep the helper column until you are satisfied.

Using SUBSTITUTE when you only need TRIM. Removing all spaces joins words together: "John Smith" becomes "JohnSmith". That is fine for identifiers, destructive for names.

Assuming TRIM handles every invisible character. It removes ordinary spaces and the leading and trailing spaces only. Non-breaking spaces, tabs copied from other programs, and stray line breaks survive it. Use CLEAN(A2) to strip non-printing characters, and wrap it with TRIM if both problems exist.

Forgetting that text that looks clean may contain stray characters. VLOOKUP and COUNTIF matches fail silently when one cell has a trailing space. If lookups are returning #N/A for values you can see, test both cells with LEN before doing anything else.

Applying trimming to numbers stored as text. After trimming, numbers may still be left-aligned text. Multiply by 1 or use Text to Columns with the General format to convert them back to real numbers.

Tips

For a one-off cleanup, the Find and Replace method is quickest: type a space in Find what and leave Replace with blank, then click Replace All. TRIM's related function TRIMRANGE is available in newer Excel builds and can trim ranges on the fly, but if you do not see it, use TRIM as shown above.

To tidy stray spaces only inside words, select the range and use the formula approach in a helper column rather than editing cells by hand.

If you clean the same report every week, build the Power Query steps once. Refreshing then applies identical trims and blank-row removal, which eliminates the most common reason numbers disagree between two versions of a spreadsheet.

When sharing a workbook, leave a note in a separate tab explaining what was cleaned, so a colleague does not wonder why the original formatting changed.

Troubleshooting

TRIM leaves the spaces in place. The characters are almost certainly non-breaking spaces or tabs. Wrap the formula as described in step 8, or use CLEAN. If a character is still stubborn, use =CODE(MID(A2,position,1)) to find its numeric code and confirm what it is.

The formula returns a #VALUE! error. Check that the cell reference points to text, not to a merged cell or a cell containing an error. Break the formula into smaller pieces, such as =LEN(A2) first, to isolate the part that fails.

Paste Special refuses to paste. Make sure you copied a range, not a single cell, and that the destination is on the same sheet or another sheet in the same workbook. Copying from a protected sheet is blocked until protection is removed.

Blank row deletion removes data unexpectedly. Go To Special selects blanks inside the used range, so a row that looks empty because a cell is blank in the selected column may still hold values elsewhere. Undo with Ctrl+Z immediately, then select only the specific column you intend to test.

Power Query changes do not show up. Click Refresh All on the Data tab. If the source file moved or was renamed, update the source path in the query settings.

Frequently Asked Questions

Does TRIM remove spaces between words?

It collapses any run of multiple spaces down to a single space. It does not delete the single spaces that separate words.

Why does TRIM not remove all my spaces?

Because the character is not an ordinary space. Non-breaking spaces, tabs and line breaks need SUBSTITUTE with CHAR(160) or CLEAN in addition to TRIM.

How do I remove every space from a cell?

Use =SUBSTITUTE(A2," ","") or Find and Replace with a space in the Find box and an empty Replace box. This joins words together, so reserve it for values like postcodes and ID numbers.

Can I trim a whole sheet at once without formulas?

Yes, through Find and Replace for simple spaces, or through Power Query's Trim transform for text columns in a table. Power Query is the better choice if the data is refreshed regularly.

Will trimming break my formulas or references?

Not if you replace the content in place with Paste Special > Values. Formulas elsewhere that point to those cells keep working; only the cell contents change from text with stray spaces to clean text.

How do I delete blank rows that are scattered through my data?

Select the range, press F5, choose Special > Blanks, then right-click a selected row header and choose Delete. Confirm you have a backup first, because deleting rows shifts everything below upward.