Excel TRIM Function (Table of Contents)
TRIM in Excel
The TRIM function is categorized under Text functions. TRIM function helps remove the extra spaces in the data leaving only a single space between words and no space characters at the start or end of the text and thus clean up the cells in the worksheet.
It is very useful when cleaning up text from other applications or environments. If you import data from any database or another application it often comes in with additional spaces either at the beginning, end or sometimes between words. Then this function can be useful in removing irregular spacing from data imported from any databases or other applications.
TRIM Formula in Excel
Below is the TRIM Formula in Excel:
Trim function arguments
There is only one argument in Trim function which is below mention.
=Text(Cell Value / Text)
Shortcut of using the formula
Click on the cell where you want to result in value then put the formula as below mention
= Trim(Cell Value / Text)
The step of using the Trim function in Excel
- Click on formula tab > Text > click on Trim
- Also, click on the function icon then manually write and search the formula.
- We get a new function window showing in below mention pictures.
- Then we have to enter the details as shown in the picture.
Put the Cell value or text value where you want to remove space from data.
- Then Click On OK.
- The Result is:
How to Use the TRIM Function in Excel?
Trim Function in Excel is very simple and easy to use. Let us now see how to use the TRIM function in Excel with the help of some examples.
4.8 (2,613 ratings)
Excel TRIM Function – Example #1
Suppose we have a column of customer names that have some space before and after the text, as well as more than one spaces between the words. So, how do we remove all extra space in a cell at a time on overall data, by copying an Excel TRIM formula across the column, and then replacing formulas with their values Let’s start to write the formula, the detailed steps are below mention.
- Write a TRIM formula for the first-row cell, A2 in our example:
The Result is:
- A position of the cursor to the lower right corner of the formula cell (B2 in this example),
- Select the range (B2:B12) and fill down the formula, up to the last cell with data.
- As a result, now you will have 2 columns original names with spaces and with formula trimmed customers’ names.
Now, replace the values in the original column with the trimmed data value, But be careful, simply copy and paste the trimmed column data value over the original column otherwise destroy your formulas and we also we lost the data. So such type of this happen, you need to copy only values, not formulas, Steps are below mention.
- Select all cells with Trim formulas (B2:B12 in this example), and copy (CTRL+C) the selected range.
- Select all cells with the original data (A2:A12)
- and Paste the data as value only not a formula, you can also use a shortcut method for paste special, (Ctrl+Alt+V). The dialog box will appear.
- Then again V for value.
- Press the Enter and result will look like
Excel TRIM Function – Example #2
Normally when we fetch data in excel from another application or any database like SQL Server, Oracle, HTML, we face such type issue for line breaking with extra space, we can say that double line issue or wrap text issue, and also ever include with a special character which is not removed with only trim. So we can use a trim function with a clean function for such type situations. Example showing as below mention pictures.
So now we can use a trim function with clean function.
- Write the formula =TRIM(CLEAN(A16))
The Result is :
- The cursor Position to the lower right corner of the formula cell (B16 in this example)
- select the range and fill down the column with the formula.
The Result is:
- Then you need to copy and paste values only, not formulas like in the first example.
Explanation of the TRIM Function in Excel
Extra Space count in a cell let’s understand
Before removing spaces in data, if we want to know how much extra space or total space in excel sheet then we get the take help of LEN function with a trim function.
If you want to get the total numbers of extra spaces in a cell then, first of all, we find the total numbers of text length using the Len function then calculate the string length without extra spaces and subtract the latter from the total length. The formula is as showing below mention.
The following screenshot shows the above formula in action:
The Result is:
Note: This function returns the count of extra spaces in a cell, but this function will be not useful as we want to count with single space also or spaces in the middle of text because trim removed only the unwanted spaces. If we want to get the total numbers of spaces in a cell we can use substitute formula with the LEN function.
As remember above we were used the trim function with a LEN function for extra spaces count. The same activity we are doing here for total spaces count uses the LEN function with substitute function. Substitute function replaces old text as a new value, in below mention example we substrates the only text value from total length count thus we found total no of space.
The Result is:
Things to Remember
- 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.
- The TRIM function was designed to trim the 7-bit ASCII space character (value 32) from the text so it only removes the ASCII space character (32) from the text.
- The TRIM function will not remove non-breaking space characters commonly used in HTML web pages.
- 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.
This has been a guide to TRIM in Excel. Here we discuss the TRIM Formula and how to use the TRIM function in Excel along with practical examples and downloadable excel template. You can also go through our other suggested articles –