The Excel Trim function takes a supplied text string and removes any spaces, except for single spaces between words or characters.
The syntax of the function is :
where the 'text' argument can be supplied to the function either directly, as a text string returned from another formula, or a reference to a cell containing text.
Note that the Trim function differs from the Clean Function in that the Trim function removes additional spaces (represented by the ASCII numeric code 32), while the Clean Function removes the non-printable characters, represented by the ASCII numerics codes 0 to 31.
The example below shows the Trim function used on four different text strings.
In all four of the above cases, the result is the string
- with no spaces at the start or end and just one space in the middle.
Further information and examples of the Excel Trim function can be found on the Microsoft Office website.