Extra spaces in Excel can cause all kinds of problems, from messy-looking spreadsheets to formulas and lookups that don’t work as expected. Fortunately, Excel includes a simple function that can quickly clean up text by removing unnecessary spaces while keeping the spaces you actually want.
In this tutorial, you’ll learn how to use the TRIM function to remove extra spaces from text in Microsoft Excel. We’ll also explain exactly what TRIM does—and what it doesn’t do—so you know when it’s the right tool for the job.
What You’ll Learn
- What the TRIM function does
- How to remove extra spaces from text
- Which spaces TRIM removes automatically
- What TRIM does not remove
- How to apply the formula to an entire column
- How to replace formulas with permanent values
Common Uses
- Cleaning imported data
- Removing extra spaces before using VLOOKUP or XLOOKUP
- Standardizing names and addresses
- Preparing data for sorting or filtering
- Cleaning customer lists
- Fixing inconsistent spacing in copied text
- Preparing spreadsheets for reports
Requirements / Compatibility
This tutorial was originally recorded in 2016, and the TRIM function continues to work the same way in current versions of Microsoft Excel, including:
- Microsoft 365
- Excel 2024
- Excel 2021
- Excel 2019
- Excel 2016
- Excel for Mac
- Excel for the web
The TRIM function has been part of Excel for many years and remains one of the most useful text-cleaning functions.
Practice & Resources
No practice workbook is required for this tutorial.
Simply open a worksheet containing text with inconsistent spacing and follow along using the examples below.
Video Tutorial
Breaking Down the Concept
The TRIM function is designed to clean up text by removing unnecessary spaces while leaving normal spacing between words intact.
TRIM Function
=TRIM(A1)
TRIM removes:
- Leading spaces (spaces before the text)
- Trailing spaces (spaces after the text)
- Multiple spaces between words
For example:
New York
becomes
New York
Notice that the single space between New and York is preserved.
Note: In most cases, TRIM is the quickest and easiest way to clean up text. However, if your data was copied from a website or PDF and the spaces won’t disappear, they’re probably non-breaking spaces. In that case, see the companion tutorial for the additional steps needed: How to Remove Spaces at the Beginning of Text in Excel
Why Use TRIM?
Extra spaces are often invisible, making them difficult to spot. They can cause problems with:
- Lookups (VLOOKUP, XLOOKUP, MATCH)
- Comparisons
- Sorting
- Filtering
- Duplicate detection
Using TRIM helps ensure your data is clean and consistent before performing other tasks.
What TRIM Doesn’t Remove
TRIM works with standard spaces entered in Excel.
If your data was copied from a website or PDF, it may contain non-breaking spaces, which look identical but use a different character behind the scenes.
If TRIM doesn’t remove the spaces, you may need to replace those non-breaking spaces first. See my companion tutorial to learn how: How to Remove Spaces at the Beginning of Text in Excel
There, I show how to identify and replace non-breaking spaces copied from websites before cleaning the text.
Step-by-Step Instructions
- Insert a blank column beside your data.
- In the first empty cell, enter:
=TRIM(A2)
- Press Enter.
- Drag the fill handle down to copy the formula to the remaining rows.
- Verify that the spacing looks correct.
- Copy the cleaned results.
- Use Paste Special → Values to replace the formulas with the cleaned text.
Additional Tips
- TRIM is often one of the first formulas to use when cleaning imported data.
- Keep your original data until you’ve confirmed the cleaned results are correct.
- If the spaces don’t disappear, your data may contain non-breaking spaces rather than standard spaces.
- If you’re combining text from multiple sources, consider cleaning each column with TRIM before merging the data.
Related Content
- Flash Fill
- TEXTJOIN
- CONCAT
- Find & Replace
- CLEAN Function
Related
How to Create an Order Form with Drop-Down Menus in Microsoft Excel
Learn how to create a professional order form in Microsoft Excel using drop-down menus, Data Validation, and named ranges. This step-by-step tutorial also covers formatting dates, ZIP codes, and credit card fields to build cleaner, more accurate spreadsheets for real-world business use.
How to Auto-Populate Fields in Excel Using a Drop-Down and VLookup
Learn how to combine a drop-down list with VLOOKUP to automatically populate customer information in Microsoft Excel. This step-by-step tutorial demonstrates a practical business workflow that can be adapted for order forms, packing lists, customer databases, contact management, and other data-entry tasks.
Stay Updated
There are two easy ways to get notified when new tutorials are published:
Subscribe on YouTube for new video tutorials: @SimpleSoftwareTutorials
or enter your email below to receive new blog posts directly in your inbox:
