Excel - TRIM Function



TRIM Function

The Excel TRIM function eliminates the extra irrelevant space from the input text string, aside from one space among words. The unwanted space, trailing space, and leading space in a text string create hindrances for users while applying lookup functions, generating charts, and printing out worksheets. For example, if you export the dataset from the external data source, you can impose the TRIM function to maintain the proper spacing in text data.

Compatibility

This flexible TRIM function is compatible with the following versions of MS Excel −

  • Excel for Microsoft 365
  • Excel for Microsoft 365 for Mac
  • Excel for the web
  • Excel 2024
  • Excel 2024 for Mac
  • Excel 2021
  • Excel 2021 for Mac
  • Excel 2019
  • Excel 2016
  • Excel 2013
  • Excel 2010
  • Excel 2007

Syntax

The syntax of the TRIM function in Excel is as follows −

TRIM (text)

Arguments

You can use the following arguments with the TRIM function −

Argument Description Required / Optional
Text The text from which you want additional spaces to be removed. Required

Points To Remember

  • The TRIM function in Excel removes only the 7-bit ASCII space character from the input string.
  • The TRIM function will not delete the nonbreaking space character introduced in the Unicode character set.

Examples of TRIM Functions

Practice the following example to leverage the TRIM function in Excel.

Example 1: How to use TRIM Function in Excel?

The TRIM function is used to remove extra spaces from a text string, leaving only single spaces between words.

Solution

Step 1 − First, consider the sample dataset where the input text is showcased in the cell range B3:B6.

How to use the TRIM function in Excel1

Step 2 − After that, select the range C3:C6 cell and type the formula =TRIM(C3) in the formula bar.

How to use the TRIM function in Excel2

Step 3 − Moreover, press the "ctrl+Enter" keys to populate the computed value in the selected range C3:C6.

How to use the TRIM function in Excel3

Example 2: LEFT TRIM Function in Excel

The LEFT TRIM function does not exist as a single function, but you can use a combination of the TRIM and LEFT functions to achieve similar results.

Solution

If you are willing to display only a few characters from the left side after deleting additional space, you may get the leverage of combining the LEFT function with the TRIM function in Excel.

First, double-click on the C3 cell and write the formula =LEFT(TRIM(B3),4).

In this expression, the TRIM function removes the extra space from the B3 cell, which refers to the string "Page Layout", then, the LEFT function fetches the first four characters from the input string.

LEFT TRIM function in Excel1

Furthermore, press the Enter tab to get the resulting value, which is "Page".

LEFT TRIM function in Excel2

Example 3: RIGHT TRIM Function in Excel

The RIGHT TRIM function is not a standalone function. It usually refers to using the TRIM function along with the RIGHT function to remove extra spaces from the right side of a text string.

Solution

You can easily extract a certain number of characters at the text string's end after removing the trailing and extra space by combining the RIGHT and TRIM functions.

Select the C2 cell and enter the formula =RIGHT(TRIM(B2),5). In this expression, the TRIM(B2) function first removes the unwanted space in the B2 cell, and then the RIGHT function returns only the five characters from the right end of the text string.

RIGHT TRIM Function in Excel1

And then hit the Enter tab.

RIGHT TRIM Function in Excel2

Example 4: LEN Function with TRIM Function

The LEN function and the TRIM function can be used together to count the number of characters in a string after removing extra spaces.

Solution

Let's suppose a text string contains a lot of extra space. When you evaluate the LEN function, the extra space character is counted as a 1, like the usual characters, creating ambiguity for Excel users.

To eliminate this problem, you can join the LEN function with the TRIM function. Type the formula =LEN(TRIM(" Investigate Accessibility")) in the B3 cell and hit the Enter tab.

Use of LEN function with TRIM function in Excel

Therefore, the resulting value is 24, representing the length of the provided string after deleting the extra space.

Download Practice Sheet

You can download and use the sample data sheet to practice the TRIM function.

Advertisements