Skip to main content
ExcelRemove All SpacesTextData CleaningSUBSTITUTETRIMString ManipulationText Functions

The Problem

Picture this: You’ve just imported a massive dataset, perhaps customer IDs, product SKUs, or a list of phone numbers. You excitedly try to run a VLOOKUP or a SUMIF, only to be met with a frustrating stream of #N/A errors or incorrect calculations. What gives? More often than not, the culprit is hidden spaces. These aren't just the obvious leading or trailing spaces; we're talking about sneaky spaces nestled within your data strings.

These invisible characters can wreak havoc on your data integrity. They prevent exact matches, cause sorting anomalies, and can lead to incorrect analytical results. While Excel's TRIM function is a great first line of defense, it often falls short when you need to truly Remove All Spaces from a string. It tackles leading, trailing, and excessive internal spaces, but it doesn't eliminate every single space. This is precisely where many users get stuck, desperately searching for a method to achieve true data sanitation.

What is REMOVE ALL SPACES in Excel? Removing all spaces in Excel is the process of eliminating every single blank character from a text string, including leading, trailing, and internal spaces. It is commonly used to standardize data, prepare text for exact matches, and clean up messy user inputs like account or product IDs, ensuring formulas function correctly.

Business Context & Real-World Use Case

Data quality is paramount in almost every professional setting. Consider a financial analyst attempting to reconcile transaction IDs from multiple systems. One system might store "TRX 12345" while another has "TRX12345" or even "TRX 12 345". Manually cleaning thousands of such entries is not only mind-numbingly tedious but also incredibly prone to human error, leading to financial discrepancies and audit headaches. In our experience, such inconsistencies are a leading cause of wasted time in data reconciliation tasks.

Similarly, in e-commerce, product SKUs or inventory codes must be absolutely precise for inventory management systems and customer orders to match up. A small space can mean the difference between a successful order fulfillment and a customer complaint. Imagine a logistics coordinator trying to match shipping labels to order numbers where half the data has rogue spaces. The resulting delays and rework cost businesses significant amounts of money.

Automating the process to Remove All Spaces provides immense business value. It ensures data consistency across disparate systems, drastically reduces the time spent on manual data cleaning, and minimizes errors that can impact financial reporting, customer service, and operational efficiency. In my years as a data analyst working with various CRMs and ERPs, I've seen teams waste countless hours trying to reconcile transaction IDs or customer records, only to find the discrepancies were due to an extra space buried in the middle. The ability to quickly Remove All Spaces is not just a time-saver; it's a critical tool for maintaining data integrity and ensuring smooth business operations. While TRIM helps, it doesn't solve the full problem; you need a more robust solution like SUBSTITUTE for comprehensive space removal.

The Ingredients: Understanding Remove All Spaces's Setup

To truly Remove All Spaces in Excel, we don't rely on a single, dedicated "Remove All Spaces" function. Instead, we use the incredibly versatile SUBSTITUTE function. Think of SUBSTITUTE as your chef's knife for text strings – it allows you to precisely replace specific characters or text within a string.

Unlike the TRIM function, which only focuses on leading, trailing, and collapsing multiple internal spaces to single ones, SUBSTITUTE offers surgical precision. It can target every instance of a specific character you define and replace it with something else – or, in our case, with nothing at all. This is the secret to effectively removing every single space from your data.

Here’s the standard syntax for the SUBSTITUTE function:

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

Let's break down each parameter for this powerful recipe:

Parameter Description
text Required. This is the original text string or a reference to the cell containing the text you want to clean. It's the ingredient you're working with.
old_text Required. This is the specific character or text string you want to replace. To Remove All Spaces, this will always be a single space character enclosed in double quotes: " ".
new_text Required. This is the character or text string that you want to replace old_text with. To completely Remove All Spaces, you will use an empty string, represented by two double quotes with nothing in between: "".
instance_num Optional. This numerical argument specifies which occurrence of old_text you want to replace. If you omit this parameter, Excel will replace every occurrence of old_text within the text string, which is exactly what we need to Remove All Spaces.

For comparison, the TRIM function's syntax is much simpler: =TRIM(text). This function is useful but doesn't offer the granular control needed to eliminate every single space.

The Recipe: Step-by-Step Instructions

Let's put SUBSTITUTE to work with a real-world scenario. Imagine you have a list of product identification numbers, customer account numbers, or even credit card numbers that have been haphazardly entered or imported, resulting in inconsistent spacing. We need to Remove All Spaces to standardize them for lookups and system processing.

Here’s our sample data:

Original Data (Column A)
PROD 123-A
JOHN DOE
CC 1234 5678 9012
Phone 555-123-4567
NoSpacesHere
Product ID 001

Our goal is to Remove All Spaces from these entries to get clean, contiguous strings in Column B.

  1. Prepare Your Data:
    Begin by entering your data into a column, for instance, Column A, starting from cell A2 as shown in the table above. Let's say we want our cleaned results to appear in Column B.

  2. Identify Your Target:
    Click on cell B2, as this is where we will enter our formula to clean the data from A2.

  3. Start with the SUBSTITUTE Function:
    In cell B2, type the beginning of our SUBSTITUTE function:
    =SUBSTITUTE(

  4. Specify the Text to Clean:
    The first argument, text, is the cell containing the data you want to process. In this case, it's A2. So, update your formula:
    =SUBSTITUTE(A2,

  5. Define the "Old Text" (What to Remove):
    We want to Remove All Spaces, so our old_text is a single space character. Remember to enclose it in double quotes.
    =SUBSTITUTE(A2, " ",

  6. Define the "New Text" (What to Replace It With):
    To effectively Remove All Spaces, we replace the old_text (the space) with nothing. This is represented by an empty string: "".
    =SUBSTITUTE(A2, " ", "")

  7. Close the Formula and Apply:
    Press Enter. Excel will immediately show the cleaned result for A2 in B2. Now, to apply this formula to the rest of your data, simply grab the fill handle (the small square at the bottom-right corner of cell B2) and drag it down to the last row of your data (e.g., B7).

Here’s what your results will look like, demonstrating how SUBSTITUTE successfully removes every space:

Original Data (A) Formula in B Result (B)
PROD 123-A =SUBSTITUTE(A2," ","") PROD123-A
JOHN DOE =SUBSTITUTE(A3," ","") JOHNDOE
CC 1234 5678 9012 =SUBSTITUTE(A4," ","") CC123456789012
Phone 555-123-4567 =SUBSTITUTE(A5," ","") Phone555-123-4567
NoSpacesHere =SUBSTITUTE(A6," ","") NoSpacesHere
Product ID 001 =SUBSTITUTE(A7," ","") ProductID001

Notice how even the multiple internal spaces in "Product ID 001" and the non-leading/trailing spaces in "CC 1234 5678 9012" are completely gone. If you had used =TRIM(A4) for the credit card number, it would have yielded CC 1234 5678 9012, failing to Remove All Spaces internally. This clearly illustrates the power and necessity of SUBSTITUTE for thorough space removal.

Pro Tips: Level Up Your Skills

You've mastered the basic recipe to Remove All Spaces, but as any good chef knows, there are always ways to refine your technique. Here are a few professional best practices and expert tips to elevate your data cleaning game:

  • Best Practice: Work on a Copy or Dedicated Column: Always perform data cleaning operations in a separate column or on a duplicate of your worksheet. This way, you retain your original data, which is crucial for auditing, verification, or if you need to revert changes. Once satisfied, you can copy the cleaned results and "paste as values" over your original data, if necessary. This minimizes the risk of irreversible data loss.

  • Tip 1: Convert Formulas to Values: After you Remove All Spaces using SUBSTITUTE and drag the formula down, your cells will contain formulas, not static values. To prevent accidental changes, reduce file size, and improve calculation speed on large datasets, select the cells with the formulas, copy them, and then "Paste Special" -> "Values" back into the same range. This cements your clean data.

  • Tip 2: Combine with CLEAN() for Comprehensive Text Cleanup: Sometimes, the "spaces" aren't just standard space characters (ASCII 32). You might encounter non-printable characters like line breaks (CHAR(10)), tabs (CHAR(9)), or other hidden formatting issues. For a truly robust cleaning routine, nest CLEAN() inside SUBSTITUTE:
    =SUBSTITUTE(CLEAN(A2), " ", "")
    The CLEAN function removes all non-printable characters, and then SUBSTITUTE steps in to Remove All Spaces, providing a super clean output.

  • Tip 3: For Large Datasets, Consider Power Query: For extremely large datasets (tens of thousands of rows or more) or data cleaning routines that need to be repeated regularly, Excel's Power Query (under the "Data" tab, "Get & Transform Data" group) offers a more powerful and efficient solution. Within Power Query, you can easily use the "Transform" -> "Format" -> "Remove Spaces" option, or create custom columns with a similar ReplaceValue operation, building a repeatable and refreshable data cleaning process.

Troubleshooting: Common Errors & Fixes

Even the best recipes can encounter snags. Here's how to troubleshoot common issues when trying to Remove All Spaces in Excel.

1. Spaces Still Present After Using TRIM()

  • What it looks like: You've applied =TRIM(A1) to a cell, but you notice there are still spaces in the middle of your text, or you're getting lookup failures you can't explain. For example, TRIM(" Product ID ") results in "Product ID", not "ProductID".
  • Why it happens: This is a classic misinterpretation of TRIM()'s functionality. The TRIM function is designed to remove leading and trailing spaces, and to reduce any sequence of multiple internal spaces between words down to a single space. It does not Remove All Spaces from a string entirely. It preserves single spaces between "words" or character groups.
  • How to fix it: To genuinely Remove All Spaces (every single instance), you must use the SUBSTITUTE function. Change your formula from =TRIM(A1) to =SUBSTITUTE(A1, " ", ""). This explicitly tells Excel to find every occurrence of a space character (" ") and replace it with nothing (""), achieving a complete elimination of spaces.

2. Unexpected Characters Appear (e.g., Non-breaking Spaces)

  • What it looks like: You've diligently used =SUBSTITUTE(A1, " ", ""), but some "spaces" or invisible characters still persist. Your cleaned data might still cause issues in lookups or data validation, even though visually it looks like you've removed all spaces. This can often happen with data imported from web pages or older systems.
  • Why it happens: Not all "spaces" are created equal. The standard space character you type (ASCII character 32) is what SUBSTITUTE(..., " ", ...) targets. However, other whitespace characters exist, such as non-breaking spaces (ASCII character 160 or HTML entity  ), tab characters (ASCII character 9), or other non-printable control characters. Your formula isn't targeting these specific, alternative whitespace characters.
  • How to fix it: You'll need to identify and substitute these specific characters.
    • Non-breaking spaces (CHAR(160)): This is a very common culprit. Nest another SUBSTITUTE call to target it: =SUBSTITUTE(SUBSTITUTE(A1, CHAR(160), ""), " ", ""). This first removes non-breaking spaces, then Remove All Spaces (standard ones).
    • Other non-printable characters: For a broader cleanup, wrap your SUBSTITUTE formula with CLEAN(): =SUBSTITUTE(CLEAN(A1), " ", ""). The CLEAN function removes most non-printable characters.
    • Identify unknown characters: If issues persist, try selecting the problematic "space" character directly from the cell, copy it (Ctrl+C), and then paste it as the old_text argument in your SUBSTITUTE formula. For example, if a tab character is the problem, you might see something like =SUBSTITUTE(A1, " ", "") (where the tab is literally pasted between the quotes).

3. Formulas Returning #VALUE!

  • What it looks like: After successfully using SUBSTITUTE to Remove All Spaces from a column, other formulas that reference this cleaned data (e.g., calculations, date conversions, or even simply formatting as a number) are now showing #VALUE!.
  • Why it happens: SUBSTITUTE operates on text strings. If your original data contained numbers or dates that were stored as "text with spaces," removing those spaces using SUBSTITUTE will still leave a text string behind. For instance, SUBSTITUTE(" 123 ", " ", "") results in "123", which is still text. Excel requires true number or date formats for mathematical operations or date functions, and it won't automatically convert a text string that looks like a number into an actual number, leading to #VALUE! errors.
  • How to fix it: You need to explicitly convert the cleaned text string to its proper data type.
    • For numbers: Wrap your SUBSTITUTE formula in the VALUE() function: =VALUE(SUBSTITUTE(A1, " ", "")). This forces Excel to interpret the text string as a numerical value.
    • For dates: If your cleaned data is meant to be a date, use the DATEVALUE() function: =DATEVALUE(SUBSTITUTE(A1, " ", "")). This converts a text string that looks like a date into a serial date number that Excel can use for date calculations. Always ensure the output of your cleaning is compatible with the functions that will use it.

Quick Reference

For those moments when you just need the essentials, here's a quick reminder of how to Remove All Spaces in Excel.

  • Syntax: =SUBSTITUTE(text, " ", "")
  • Most Common Use Case: To completely eliminate every single space character (leading, trailing, and internal) from a text string, often for standardizing data like product IDs, phone numbers, credit card numbers, or any other alphanumeric identifier that requires strict formatting.

Related Functions

👨‍💻

Written by The Head Chef

Former 10-year Financial Analyst who survived countless month-end closes. I build these recipes to save you from weekend-ruining spreadsheet errors.

Read the full story →

You might also find these useful 💡