TRIM()

Syntax. TRIM(text)

Definition. This function deletes the spaces in the text that are not used as delimiters between words.

Arguments

BackgroundYou can use the TRIM() function for text imported from other applications that might contain unnecessary spaces. Redundant spaces at the beginning or end of text can be unhelpful, for example, for a mail merge or when searching for a string in a list.

If the string does not contain leading or trailing spaces, the result is the input string.

Assume that after you import a set of data, you notice that it contains trailing spaces. You need to remove these spaces to further process the data. You cannot use the Replace command (Ctrl+H), because you don’t want to delete the spaces between words. You can use the TRIM() function to remove the redundant spaces. The following table shows some of the possible results for different input values:

Formula

Result

=TRIM(“August”)

The word August isn’t changed.

=TRIM(“August “)

The trailing space after August is removed.

=TRIM(“  August  ”)

The two leading spaces before August are removed.

=TRIM(“   August   ”)

The two leading spaces and the three trailing spaces are removed.

=TRIM(“ August the Strong ”)

The leading space and the trailing space are removed.

See Also

CLEAN(), MID(), SUBSTITUTE()