How to Use the TRIM Function in Google Sheets | Remove Extra Leading and Trailing Spaces
How to Use the TRIM Function
The TRIM function removes unnecessary spaces from the beginning and end of a text string and reduces consecutive spaces between words to a single space. It is essential for cleaning data pasted from external systems and preventing VLOOKUP mismatches.
Syntax
=TRIM(text)
- text: The text string or cell reference from which you want to remove extra spaces (required).
Example Using a Table
Here is an example of cleaning up extra spaces (␣ represents a space) in the roster data below.
| Row | Column A (Raw Data) | Column B (After TRIM) |
|---|---|---|
| 1 | Raw Data | Cleaned |
| 2 | ␣␣Yamada Taro␣ |
=TRIM(A2) → Yamada Taro |
| 3 | Suzuki␣␣␣Ichiro |
=TRIM(A3) → Suzuki Ichiro |
| 4 | Sato Hanako |
=TRIM(A4) → Sato Hanako |
- Formula:
=TRIM(A2) - Result:
Yamada Taro
As shown in row 3, multiple spaces between words are also neatly collapsed into a single space.
Common Errors and Notes
- Non-Breaking Spaces (
CHAR(160)) Are Not Removed: Special whitespace characters (non-breaking spaces) often included when copying from websites cannot be removed byTRIMalone. Replace them with normal spaces first usingSUBSTITUTE, such as=TRIM(SUBSTITUTE(A2, CHAR(160), " ")). - Line Breaks Are Not Removed: If you also want to strip line breaks (
CHAR(10)), combine it withCLEAN:=TRIM(CLEAN(A2)). - Original Cells Are Not Overwritten: Because the cleaned result is output into another cell containing the formula, copy and “Paste values only” if you want to replace the original data.
Frequently Asked Questions
Q. Can the TRIM function remove full-width spaces as well?
A. Yes. Google Sheets' TRIM function removes both half-width and full-width spaces from the beginning and end of a text string.
Q. Does TRIM remove all spaces in the middle of a string?
A. No, a single space between words is preserved. If there are two or more consecutive spaces, they are collapsed into a single space. To remove all spaces inside a string, use the SUBSTITUTE function.