ID EN
#Text

TRIM

Excel Functions

Remove extra spaces from text

Syntax

EXCEL
=TRIM(text)

Arguments

Parameter Description
text The text from which to remove extra space.

Return Value

Text with extra spaces removed.

Details

The TRIM function strips extra spaces from text, leaving only a single space between words, and removing any leading or trailing space. For example: The TRIM function can be used together with the CLEAN function to remove extra space and strip out other non-printing characters: TRIM often appears in other more advanced text formulas. For example, the formula below will count the number of words in cell A1: Because this formula depends on single spaces to get an accurate word count, TRIM is used to normalize space before the count is calculated. Full description here.

Examples

Example 1

The TRIM function strips extra spaces from text, leaving only a single space between words, and removing any leading or trailing space. For example:

EXCEL
=TRIM("   A stitch    in time.   ")  // returns "A stitch in time."
Example 2

The TRIM function can be used together with the CLEAN function to remove extra space and strip out other non-printing characters:

EXCEL
=TRIM(CLEAN(A1)) // trim and clean
Example 3

TRIM often appears in other more advanced text formulas. For example, the formula below will count the number of words in cell A1:

EXCEL
LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1

See Also

CLEAN