How to Use TRIM function in Excel

In this article, we will learn about how to use the TRIM function in Excel to remove all spaces and non-breaking spaces.

What is the TRIM function and why would we need to use this function ?

When we need to perform any operation on a cell, we need  to be sure that no extra space interferes. For Example leading spaces or trailing spaces. So this function removes the leading and trailing spaces. So that all values come in the same order.

TRIM function is a TEXT function in Excel used to remove all extra spaces from the text string except for single space between words.

Syntax:

=TRIM(text)

text : text value in quotes or cell reference

Example :

All of these might be confusing to understand. Let's understand how to use the function using an example. Here we have some values to test the function.

Use the formula:

=TRIM(A2)

As you can all the Leading and trailing spaces are removed with single space from the Text.

How TRIM function is different from CLEAN function

All of these might be confusing to understand. So, let's test this formula via running it on the example shown below. Here we have some values to test the CLEAN function in Excel.

Use the formula:

=CLEAN(D3)

D3 : value in D3 cell. Using cell reference

Extra linespaces are removed from the value in D3 cell. Now remove characters from the value in D4 cell. Just copy the formula from E3 cell to other cells using Ctrl + D.

Characters between text removed using function.

Use with other functions like TRIM function:

Trim function in Excel removes extra spaces from the text and CLEAN function removes mentioned characters and line spaces.

Use the formula:

= TRIM ( CLEAN ( D5 ) )

D3 : value in D3 cell. Using cell reference

Here there is a character between "M" and "20" which is removed by CLEAN function. Extra spaces in the beginning and ending of the text which is removed by TRIM function. Spaces (not line space) between characters remains as it is. For that you need to use SUBSTITUTE function

Here are all the observational notes using the TRIM function in Excel
Notes :

  1. Text value can be a number or text or mixed.
  2. The function returns #NAME? Error when text is provided without quotes.
  3. Use cell reference (preferable) to input a text value.

Hope this article about How to Use TRIM function in Excel is explanatory. Find more articles on editing text values and related Excel formulas here. If you liked our blogs, share it with your friends on Facebook. And also you can follow us on Twitter and Facebook. We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write to us at info@exceltip.com.

Related Articles :

How to use the CLEAN function in Excel: Clean function is used to clean up unprintable characters from the string. This function is mostly used with the TRIM function to clean up imported foreign data.

Replace text from end of a string starting from variable position: To replace text from the end of the string, we use the REPLACE function. The REPLACE function uses the position of text in the string to replace.

How to Check if a cell contains one of many texts in Excel: To find check if a string contains any of multiple text, we use this formula. We use the SUM function to sum up all the matches and then perform a logic to check if the string contains any of the multiple strings.

Count Cells that contain specific text: A simple COUNTIF function will do the magic. To count the number of multiple cells that contain a given string we use the wildcard operator with the COUNTIF function.

Excel REPLACE vs SUBSTITUTE function: The REPLACE and SUBSTITUTE functions are the most misunderstood functions. To find and replace a given text we use the SUBSTITUTE function. Where REPLACE is used to replace a number of characters in string…

How to Use TRIM function in Excel: The TRIM function is used to trim strings and clean any trailing or leading spaces from string. This helps us in the cleaning process of data a lot.

Replace text from end of a string starting from variable position: To replace text from the end of the string, we use the REPLACE function. The REPLACE function use the position of text in the string to replace.

How to Check if a string contains one of many texts in Excel: To find check if a string contains any of multiple text, we use this formula. We use the SUM function to sum up all the matches and then perform a logic to check if the string contains any of the multiple strings.

Count Cells that contain specific text: A simple COUNTIF function will do the magic. To count the number of multiple cells that contain a given string we use the wildcard operator with the COUNTIF function.

Popular Articles :

How to use the IF Function in Excel : The IF statement in Excel checks the condition and returns a specific value if the condition is TRUE or returns another specific value if FALSE.

How to use the VLOOKUP Function in Excel : This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets.

How to Use SUMIF Function in Excel : This is another dashboard essential function. This helps you sum up values on specific conditions.

How to use the COUNTIF Function in Excel : Count values with conditions using this amazing function. You don't need to filter your data to count specific values. Countif function is essential to prepare your dashboard.

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.