Vai al contenuto principale

How to Remove Spaces in Excel: TRIM(), SUBSTITUTE() and More

Remove unnecessary spaces, including leading, trailing, and extra spaces, to keep your data clear. This guide covers TRIM(), SUBSTITUTE(), and CLEAN() functions, plus practical tips to ensure spreadsheets remain accurate and easy to work with.
Aggiornato 4 mar 2026  · 6 min leggi

I once got a spreadsheet with 500+ entries that looked fine initially but wouldn’t calculate totals correctly. I didn’t know why, but later, it turned out that hidden spaces were causing all sorts of trouble. If you handle data in Excel, you may have encountered similar situations. These spaces often come when you import data from other sources.  

In this guide, I’ll show you different methods to remove unwanted spaces in Excel. You'll get step-by-step instructions and practical examples for each method to save you the headaches I went through. However, if you’re just starting, check out our Data Analysis in Excel course or the Excel Fundamentals skill track. 

TL;DR

  • Hidden spaces break formulas — leading, trailing, or extra spaces cause VLOOKUP() mismatches, SUM() returning zero, and failed comparisons.
  • TRIM() — use for most cases; removes leading/trailing/extra spaces, keeps one space between words.
  • SUBSTITUTE() — use to remove ALL spaces including between words, or to target specific characters.
  • CLEAN() — combine with TRIM() to strip non-printable characters from imported data.
  • Non-breaking spaces? Use =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))) — the all-in-one fix.
  • Find & Replace (Ctrl+H) — fastest option for removing spaces directly in-place, no helper column needed.

Understanding Spaces in Excel

Before we remove spaces, let’s understand the types of spaces that may be lurking in your data:

  • Leading spaces: Spaces at the start of a cell.
  • Trailing spaces: Spaces at the end of a cell.
  • Extra spaces between words: More than one space between words.
  • Non-breaking spaces: Special spaces that look normal but behave differently.

These spaces can slip into your data from importing files, manual entry mistakes, inconsistent formatting, or even copying and pasting from other sources.

different types of spaces in Excel

Types of spaces. Image by Author. 

Different Ways to Remove Spaces in Excel

Though spaces may seem minor, they can cause big problems. Formulas might not work, comparisons may fail, and calculations could turn out wrong. Before jumping into solutions, I’d recommend the following:

  • Back up your data: Always make a copy of your data before making changes. This ensures you can recover the original data if something goes wrong.
  • Check formatting: Ensure consistent formatting in your cells, such as text case and number formats, for cleaner and more reliable results.

Now, let’s explore the best methods to remove spaces in Excel.

Method 1: Use the TRIM() function to remove extra spaces

The TRIM() function removes unnecessary spaces, such as leading, trailing, and multiple spaces between words, except for the single-space character. For a complete reference, see our guide to the TRIM() function in Excel. Here's how to use it:

  1. Create a helper column next to your data.

  2. In the first cell of the helper column, enter the formula: =TRIM(A2).

  3. Press Enter and drag the formula down to apply it to all rows.

Using TRIM function to remove all the spaces in Excel.

Use TRIM() to remove the spaces. Image by Author.

Tip — replace the original data: After applying TRIM() in the helper column, copy the trimmed cells, then right-click the original column and select Paste Special > Values Only (shortcut: Alt+E+S+V or Ctrl+Shift+V on Mac). This pastes just the cleaned values, letting you delete the helper column afterward.



Method 2: Use the SUBSTITUTE() function

The SUBSTITUTE() function removes every space (including the space between words) from a cell and replaces any character, including spaces, with something else. It cleans numerical data, such as removing spaces that separate digits. 

Its basic syntax is:

=SUBSTITUTE(text, old_text, new_text, [instance_num])

Here’s how to apply it and remove all the spaces: 

  1. Create a helper column.

  2. Enter the formula: =SUBSTITUTE(A2," ","").

  3. Press Enter and drag it down to apply it to all rows.

all the spaces are removed using substitute function in excel.

Using the SUBSTITUTE() function. Image by Author.

Method 3: Data cleanup with Find & Replace

If you want a quick and easy fix, I’d recommend Excel’s Find & Replace tool — it can handle extra spaces between words. Here’s how:

  1. Select your data range.

  2. Press Ctrl+H to open the Find & Replace dialog.

  3. In the Find what field, enter two spaces.

  4. In the Replace with field, enter a single space.

  5. Click Replace All.

using Find & replace feature in Excel

Cleaning spaces using the Find & Replace feature. Image by Author.

Repeat the steps until Excel shows the message, We couldn't find anything to replace. Note that this method reduces leading and trailing spaces to a single space but does not remove them completely. It only addresses spaces between words. 

Remove line breaks

Sometimes data pasted from the web or other sources contains line breaks (Alt+Enter characters, CHAR(10)) that look like extra spacing. The TRIM() function won’t catch these. To remove them:

  1. Select the cells you want to clean.

  2. Press Ctrl+H to open Find & Replace.

  3. In the Find what field, press Ctrl+J (a blinking cursor appears — that’s the line break character).

  4. Leave the Replace with field empty (or type a space to avoid merging words).

  5. Click Replace All.

Alternatively, use the formula: =TRIM(CLEAN(A1)) — the CLEAN() function strips line breaks (CHAR(10)) and other non-printable characters (ASCII 1–31) in one step.

Method 4: Use the CLEAN() function to remove non-printing characters

When we import or copy data from external sources, we often get non-printable characters that can disrupt data operations. You can use the CLEAN() function to remove them or, even better — combine it with TRIM() to clean up extra spaces.

Here’s how you can do it: 

  1. Enter the formula: =TRIM(CLEAN(A2)) in a helper column.

  2. Press Enter and drag the formula down.

use CLEAN and TRIM functions together to remove spaces in Excel.

Combine TRIM() and CLEAN() to remove spaces. Image by Author.

Method 5: Advanced method – use Excel Add-Ins for faster results

You can use the third-party add-in Ablebits Ultimate Suite for Excel. Its Trim Spaces tool cleans up data quickly. With one click, it takes care of everything. This includes leading and trailing spaces, line breaks, extra blanks between words, and non-breaking spaces. So, if you’re like me who works with large datasets regularly, it can save you so much time. 

Here is how to use it:

  1. Select the range of cells to clean.

  2. Open the Ablebits Data tab and click Trim Spaces.

  3. From the options pane, select what you want to remove and click Trim.

TRIM spaces in Excel

Trim spaces with Excel’s add-in. Image by Author.

Specific Solutions for Common Space Removal Scenarios in Excel

Now, let’s look at a few common scenarios you may run into and how you can quickly fix them.

Remove extra spaces

Extra spaces can make your data look messy and hard to work with. You can use the TRIM() function to clean them up while keeping one space between words. For example, I have a couple of data entries with inconsistent spacing. To sort this, I entered the following formula in cell B2 and applied it to all rows:

=TRIM(A2)

Use TRIM() to remove extra spaces in Excel.

Use TRIM() to remove extra spaces. Image by Author.

Remove leading spaces 

Sometimes, we have to keep multiple spaces between words to make our data easier to read, but remove any spaces from the start. The TRIM() function works well but removes all the spaces in the text. So, in such a case where you want to remove only the leading spaces while keeping the rest intact, use this advanced formula:

=MID(A2,FIND(MID(TRIM(A2),1,1),A2),LEN(A2))

Here’s how the formula works: It locates the first non-space character and keeps everything from that point forward. This way, it keeps spaces between words and trims only at the start of the cell (leading spaces).

removing only leading spaces in Excel.

Remove only leading spaces. Image by Author.

Remove trailing spaces

Trailing spaces are extra spaces that appear after text or numbers in a cell. These invisible characters can cause problems like formula errors, where cells that appear identical fail to match in functions like VLOOKUP() or MATCH(). To avoid this, use the TRIM() function. For example, I put this formula in cell B2 and then applied it to all rows to remove extra spaces from my data.

=TRIM(A2)

Remove trailing spaces using TRIM function in Excel.

Removing trailing spaces. Image by Author.

Remove spaces before numbers

While TRIM() works great for cleaning up spaces in text, you may face issues using it with numeric data. Let me show you what happens:

=TRIM(A2)

TRIM() function fails to remove spaces correctly in Excel.

The TRIM() function doesn’t remove the spaces correctly. Image by Author.

You can see, the TRIM() removed spaces before a number, but Excel doesn't treat the result as a number anymore — it treats the outcome as text. Here’s how to spot this:

  • The data is left-aligned instead of right.

  • Look at your status bar - it only shows you how many cells you've selected (COUNT), not their total. 

  • If you try to add up these cells with SUM(), you'll get zero.

You need to turn the text back into a number to fix this. To do so, you can either multiply by 1 or use this formula:

=VALUE(TRIM(A2))

This removes spaces and ensures Excel treats the data as numbers.

Combine VALUE() and TRIM() to remove spaces before numbers in Excel.

Combine VALUE() and TRIM() to remove spaces before numbers. Image by Author.

Remove spaces from a string 

If you want to remove all spaces, including those between words, use the SUBSTITUTE() function:

=SUBSTITUTE(A2, " ", "")

You can see the formula cuts off every space from the string.

Remove the spaces using SUBSTITUTE function in Excel.

Remove the spaces using the SUBSTITUTE() function. Image by Author.

Remove special characters and unnecessary spaces  

SUBSTITUTE() is great when you want to remove specific characters from your text. But you can pair it with TRIM() to clean up special characters and spaces in one go. For example, if I want to remove & and clean up spaces, I use this formula:

=TRIM(SUBSTITUTE(A2, "&", ""))

You can see how TRIM() and SUBSTITUTE() work when used together versus SUBSTITUTE() alone.

Combine TRIM() and SUBSTITUTE() to clean spaces in Excel.

Combine TRIM() and SUBSTITUTE() to clean spaces. Image by Author.

Common Problems and Solutions

Sometimes, when I copy or import data from other sources, a lot of non-breaking spaces and strange characters appear in my data. Here’s how I handle them: 

Non-breaking spaces that TRIM() doesn’t handle

The TRIM() function removes extra spaces, but it doesn’t work for non-breaking spaces (character code 160). These often show up in data from web pages or formatted sources. To fix this, I use:

=TRIM(SUBSTITUTE(A1, CHAR(160), ""))

This formula removes non-breaking spaces entirely. If you want to replace them with regular spaces first (so TRIM() can then clean up any extras), use: =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))) — the gold-standard formula for stripping all space types at once.

Hidden characters or pasted data problems

Sometimes, other hidden characters sneak in, like tabs or line breaks. To find them, I use CODE() to check the character’s position:

  • First character: =CODE(LEFT(A1,1))

  • Last character: =CODE(RIGHT(A1,1))

  • Specific position: =CODE(MID(A1, n, 1)) (Replace n with the position number.)

This is the formula I use:

=CODE(RIGHT(C2,1))

Once I know the code, I remove it with TRIM() and SUBSTITUTE(). For example, to remove tabs (code 115), I use:

(SUBSTITUTE(C2, CHAR(115), “ “))

remove the hidden spaces using CODE, TRIM and SUBSTITUTE functions in Excel.

Use CODE(), TRIM(), and SUBSTITUTE() to remove spaces. Image by Author.

Quick Method Comparison

Not sure which method to use? This table maps each scenario to the right tool:

Scenario Best Method Formula / Shortcut
Remove leading & trailing spaces TRIM() =TRIM(A1)
Remove ALL spaces (including between words) SUBSTITUTE() =SUBSTITUTE(A1," ","")
Quick in-place cleanup, no formula needed Find & Replace Ctrl+H
Data imported from web or other apps TRIM() + CLEAN() =TRIM(CLEAN(A1))
Non-breaking spaces (CHAR(160)) from web pages TRIM + CLEAN + SUBSTITUTE =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," ")))
Spaces mixed with numeric data VALUE() + TRIM() =VALUE(TRIM(A1))
Remove line breaks Find & Replace or CLEAN() Ctrl+H → Ctrl+J or =TRIM(CLEAN(A1))
Large dataset, frequent cleaning needed Excel Add-In (Ablebits) Ablebits Data > Trim Spaces

Final Thoughts

In this guide, I showed you methods like TRIM() for simple fixes, SUBSTITUTE() for advanced problems, and add-ins in case you will be removing spaces frequently and want a different process. Each method suits different data types, so choose the one that fits your needs. For a broader look at keeping your spreadsheets clean, see our guide to data cleaning in Excel.

If you want to strengthen your skills further, check out the DataCamp Data Analysis with Excel Power Tools skill track. It offers step-by-step lessons to help you master Excel and improve your data-cleaning techniques.

Advance Your Career with Excel

Gain the skills to maximize Excel—no experience required.

Start Today for Free

Laiba Siddiqui's photo
Author
Laiba Siddiqui
LinkedIn
Twitter

I'm a content strategist who loves simplifying complex topics. I’ve helped companies like Splunk, Hackernoon, and Tiiny Host create engaging and informative content for their audiences.

FAQs About Removing Spaces in Excel

Can I use Power Query to remove spaces in Excel?

Yes, here’s how you can do so:

  • Select your data and load it into Power Query.
  • In the Power Query Editor, select the column you want to clean.
  • Use the Transform tab and select Trim to remove leading and trailing spaces.

Use Replace Values to remove extra spaces between words or specific characters. Once cleaned, you can load the data back into Excel.

How do I remove dashes and extra spaces from a cell in Excel?

You can use the TRIM() and SUBSTITUTE() functions to remove dashes and extra spaces from a cell. Here's the formula: =TRIM(SUBSTITUTE(A11, "-", ""))

Can I remove spaces from a text string using Flash Fill in Excel?

Flash Fill can remove spaces if you provide a pattern. For example, if John Doe is in A2 and you want JohnDoe without spaces, type JohnDoe in B2, then press Ctrl + E to trigger Flash Fill.

Can I remove spaces and convert text to uppercase at the same time?

Yes, combine the SUBSTITUTE() and UPPER() functions to remove spaces and convert text to uppercase: =UPPER(SUBSTITUTE(A2, " ", ""))

What is the fastest way to remove spaces in Excel without a formula?

Use Find & Replace (Ctrl+H). In the Find what field, type one or two spaces. Leave Replace with empty and click Replace All. This removes spaces directly in the selected cells with no helper column needed. For a pattern-based approach, Flash Fill (Ctrl+E) can also remove spaces if you provide one example of the desired output.

Why does TRIM() not work on my data?

TRIM() only removes regular spaces (ASCII 32). If your data contains non-breaking spaces (CHAR(160), common in web-pasted text) or non-printable characters, TRIM() alone won’t work. Use the all-in-one formula: =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))). You can identify the mystery character with =CODE(LEFT(A1,1)) or =CODE(RIGHT(A1,1)).

Argomenti

Learn Excel with DataCamp

Corso

Preparazione dei dati su Excel

3 h
77.9K
Capire come preparare i dati di Excel attraverso funzioni logiche, formule annidate, funzioni di ricerca e tabelle Pivot.
Vedi dettagliRight Arrow
Inizia il corso
Mostra altroRight Arrow
Correlato

Tutorial

Use the TRIM() Function in Excel: Fix Any Spacing Issue

Explore how the TRIM() function removes extra spaces and cleans up your data. Combine it with other functions like SUBSTITUTE(), CLEAN(), and VALUE() to fix all kinds of formatting issues.
Laiba Siddiqui's photo

Laiba Siddiqui

Tutorial

CLEAN() Function in Excel: The Best Way to Remove Non-Printable Characters

Excel's CLEAN() function cleans up text by removing non-printable characters. Combine it with other functions like TRIM(), SUBSTITUTE(), and REPLACE() for a cleaner spreadsheet.
Laiba Siddiqui's photo

Laiba Siddiqui

Tutorial

How to Clean Data in Excel: A Beginner's Guide

Learn essential data cleaning techniques in Excel, including removing duplicates, handling missing values, and maintaining consistent formatting.
Laiba Siddiqui's photo

Laiba Siddiqui

Tutorial

Remove Blank Rows in Excel: 4 Easy Methods

Learn how to remove extra rows quickly using sorting, formulas, and VBA, depending on what works best for you.
Laiba Siddiqui's photo

Laiba Siddiqui

Tutorial

How to Use Excel CONCAT(): A Quick Guide

Learn how to merge text, numbers, and cell ranges in Excel, reduce manual entry, and keep your data tidy and well-organized.
Josef Waples's photo

Josef Waples

Tutorial

Excel Substring Techniques: Extract and Format Text

Learn how to extract and format text position or delimiter using Excel substring functions, including LEFT(), RIGHT(), MID(), and more, with step-by-step instructions.
Laiba Siddiqui's photo

Laiba Siddiqui

Mostra altroMostra altro