Quick Navigation
TRIM Function
Summary
The TRIM function cleans text by removing all extra spaces, keeping only single spaces between words. Perfect for standardizing imported data, preparing text for searches, or fixing spacing issues from other applications.
Syntax
TRIM(text)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | Text |
Yes | Text or cell reference containing extra spaces for cleaning |
Using the TRIM Function
TRIM is essential for data preparation, especially when working with text imported from external sources like databases, web pages, or CSV files that often contain inconsistent spacing. It standardizes text appearance and prevents issues in lookups, sorting, and matching operations.
Common TRIM Examples
Basic Text Cleanup
=TRIM(" First Quarter Earnings ")
Removes leading, trailing, and extra internal spaces, returning "First Quarter Earnings"
Clean Imported Data
=TRIM(A2)
Cleans customer names or addresses imported from other systems with irregular spacing
Fix Multiple Spaces
=TRIM(SUBSTITUTE(A2," ","*"))
Advanced cleaning - replaces double spaces first, then trims
Frequently Asked Questions
Common Errors and Solutions
#VALUE! error
Cause: text argument is not text or reference to text
Solution: Ensure the argument contains text data
Non-breaking spaces remain
Cause: Data contains Unicode spaces (160) not handled by TRIM
Solution: Use =TRIM(SUBSTITUTE(A1,CHAR(160)," ")) to convert first
Notes
- TRIM does NOT remove non-breaking spaces (HTML equivalent)
- Ideal preprocessing step before VLOOKUP, MATCH, or text comparisons
- Combine with CLEAN for comprehensive text sanitization
- Processes only standard space characters (ASCII 32)
Compatibility
Available in: Excel 2007, Excel 2010, Excel 2013, Excel 2016, Excel 2019, Excel 2021, Excel 365, Excel for Mac, Excel Online
Not available in: Excel 2003, Excel XP, Excel 2000, Excel 97
Content last reviewed: December 11, 2025
Update frequency: As needed
Excel versions tested: Excel 2007+