A text function used to remove spaces from a text string, except for a single space between words.

Removes extra spaces in the data

What is the TRIM Function?

The TRIM Function[1] is categorized under Excel Text functions. TRIM helps remove the extra spaces in data and thus clean up the cells in the worksheet.

In financial analysis, the TRIM function can be useful in removing irregular spacing from data imported from other applications.

Formula

=TRIM(text)

  1. Text (required argument) – This is the text from which we wish to remove spaces.

A few notes about the TRIM Function:

  • TRIM will remove extra spaces from text. Thus, it will leave only single spaces between words and no space characters at the start or end of the text.
  • It is very useful when cleaning up text from other applications or environments.
  • TRIM only removes the ASCII space character (32) from the text.
  • The Unicode text often contains a non-breaking space character (160) that appears in web pages as an HTML entity. It will not be removed with TRIM.

How to use the TRIM Function in Excel?

TRIM is a built-in function that can be used as a worksheet function in Excel. To understand the uses of the function, let’s consider a few examples:

Example 1

Suppose we are given the following data from an external source:

A text function used to remove spaces from a text string, except for a single space between words.

For trimming the spaces, we will use the following function:

A text function used to remove spaces from a text string, except for a single space between words.

We get the results below:

A text function used to remove spaces from a text string, except for a single space between words.

Example 2

Let us see how the TRIM function works for numbers. Suppose we are the given the data below:

A text function used to remove spaces from a text string, except for a single space between words.

The formula to use is:

A text function used to remove spaces from a text string, except for a single space between words.

Using the TRIM function, we will get the following result:

A text function used to remove spaces from a text string, except for a single space between words.

As you can see above, the trimmed values are text strings, while we want numbers. To fix this, we will use the VALUE function along with the TRIM function, instead of the above formula:

A text function used to remove spaces from a text string, except for a single space between words.

The above formula removes all leading and trailing spaces, if any, and turns the resulting value into a number, as shown below:

A text function used to remove spaces from a text string, except for a single space between words.

Example 3

To join multiple cell values with a comma, we can use a formula based on the SUBSTITUTE and TRIM functions. Suppose we are given the following data:

A text function used to remove spaces from a text string, except for a single space between words.

The formula to use is:

A text function used to remove spaces from a text string, except for a single space between words.

The formula first joins the values in the four cells to the left using the concatenation operator (&) and a single space between each value. The TRIM function is used to “normalize” all spacing. TRIM automatically strips space at the start and end of a given string and leaves just one space between all words inside the string. It takes care of extra spaces caused by empty cells. SUBSTITUTE is used to replace each space (” “) with a comma and space (“, “). We used a delimiter to join cells.

We get the results below:

A text function used to remove spaces from a text string, except for a single space between words.

Click here to download the sample Excel file

Additional Resources

Thanks for reading CFI’s guide to this important Excel function. By taking the time to learn and master these functions, you’ll significantly speed up your financial modeling. To learn more, check out these additional CFI resources:

  • Excel Functions for Finance
  • Advanced Excel Formulas Course
  • Advanced Excel Formulas You Must Know
  • Excel Shortcuts for PC and Mac

Article Sources

  1. TRIM Function

Which text function would remove all spaces from a string except for single spaces between words?

The TRIM function is relatively straightforward. Simply give it some text and it removes all spaces from the text except for single spaces between words. The TRIM function was designed to trim only the ASCII space character from text.

How do I remove spaces from a text string?

If you just want to remove the extra space, leading spaces and the trailing spaces from strings, you can apply this formula: Select a cell where you will put the result, and type this formula =TRIM(A2), press Enter key, and then the drag the auto fill handle over the cells which need this formula.

What function would you use to remove blank spaces from the beginning of a text string?

The TRIM Function The TRIM function removes all spaces in a text string, except for single spaces between words.

Which of this function is used to remove more than one space?

You use the TRIM function in Excel removes extra spaces from text. It deletes all leading, trailing and in-between spaces except for a single space character between words. Where text is a cell that you want to remove excess spaces from.