The Excel TRIM function is a Text formula which can remove the leading and trailing sections of a text string, and replace extra spaces between words with one. As the name suggests, the formula essentially “trims” the extra spaces in the target string, and removes extra spaces. In this guide, we’re going to show you how to use TRIM function and also throw in some tips and error handling methods.


Supported versions

  • All Excel versions

Excel TRIM Function Syntax

TRIM(text)


Arguments

text

The text string you want to trim.



Example

You can enter a static text or a cell reference for the text parameter in the Excel TRIM function. For example,

=TRIM(”       2 + 2   equals      5       “)
returns the string “2 + 2 equals 5“. The spaces are removed except for the ones between characters or words.

Download Workbook


Summary and Tips

  • Use the Excel TRIM function to remove extra spaces on a string that you’ve copied from another source.
  • TRIM removes 7-bit ASCII space characters (value 32) from the target text. The nonbreaking space character ( ), which is commonly used in Web pages, is not supported.
  • There is also a VBA function named TRIM which works similarly. The following code assigns the string “Ministry of Truth” to variable named Trimmed.

Dim Trimmed As String

Trimmed = Trim(”    Ministry   of      Truth          “)