Quick Answer

TRIM Function

TRIM cleans up text by removing leading, trailing, and extra spaces between words.

✓ Excel✓ Google SheetsExcel All versions

Syntax

TRIM
(text)

Parameters

ParameterDescriptionRequired
textThe text string to trim.Required

Basic Example

Remove extra spaces from text

=TRIM(" Hello World ")
ResultHello World

Removes leading and trailing spaces, leaving single spaces between words.

Advanced Examples

Example 1: Clean imported data

Data cleaning

Trim whitespace from imported CSV data

=TRIM(A1)
Result: Clean text
Removes unwanted spaces from data imported from external sources.

Example 2: Trim and uppercase for consistent lookups

Data matching

Prepare text for VLOOKUP by trimming and uppercasing

=UPPER(TRIM(A1))
Result: HELLO WORLD
Ensures consistent text formatting for reliable lookups.

How TRIM Works

TRIM removes all spaces from the text except for single spaces between words. It removes leading, trailing, and consecutive internal spaces.

1
Select output cell
Choose where the result should appear.
2
Enter formula
Type =TRIM(text).
3
Press Enter
The result shows the cleaned text.

Important Notes & Limitations

  • TRIM only removes regular spaces (ASCII 32).

  • For non-breaking spaces (CHAR(160)), use SUBSTITUTE to replace them first.

Common Errors & Fixes

#VALUE!Invalid argument

Fix: Ensure the argument is text or a cell reference.

Download Practice File

Practice TRIM with Real Data

Download a sample CSV file with pre-populated data and practice exercises for the TRIM function. Works in both Excel and Google Sheets.

Works in Google SheetsCompatible with ExcelIncludes exercises

File format: CSV (comma-separated values) - opens in Excel, Google Sheets, and all spreadsheet apps

Frequently Asked Questions

Does TRIM remove non-breaking spaces?
No, use =TRIM(SUBSTITUTE(A1, CHAR(160), " ")) to remove non-breaking spaces.
Can I trim numbers?
Yes, numbers are converted to text and trimmed.