Additional spaces are often added to the text when we copy or import text in Google Sheets. These additional spaces can cause trouble in function execution. An easy solution to this problem is to use the TRIM function to remove these additional spaces. Here, in this article, I’ll discuss a few examples of how to use the TRIM function in Google Sheets.
A Sample of Practice Spreadsheet
What Is TRIM Function in Google Sheets?
The TRIM function in Google Sheets removes leading, trailing, and repeated spaces.
The syntax of TRIM function is as follows:
|Text||Required||Reference or text containing the text to be trimmed|
The formula TRIM (“ Supply Chain ”) will show Supply Chain as output.
4 Easy Examples of Using TRIM Function in Google Sheets
Here, we’ll demonstrate 4 easy examples of how to use the TRIM function in Google Sheets. The TRIM function will also be combined with other functions like the ARRAYFORMULA, SPLIT, and FLATTEN functions for advanced operations. Now, let’s go through the methods.
1. Applying Only TRIM Function
First, let’s get used to our datasheet for this method. The datasheet consists of several input texts with additional leading, trailing, and repeated spaces. The text lengths are also shown using the LEN function. We will use the TRIM function to remove the additional spaces.
1.1 Input Direct Text Value
We can input direct text values as the argument for the TRIM function.
- First, select Cell D5 and type in the following formula and then press the Enter key-
- To check whether the function has actually worked as required, select Cell E5 and type in the following formula. After that, press Enter As you can see, the text length has changed from 17 to 9.
- Similarly, perform the trim operations in other cells of Column D and check the trimmed text length using the LEN function.
1.2 Enter Cell Reference
Using direct text values as an argument can be tedious for large texts or large datasets. An alternative is to use cell references instead.
- Select Cell D5 and then type in the following formula. Then, press the Enter key to see the trimmed text.
- Use the LEN function as described previously to check the length of the text after trimming.
- Now, select Cell D5 and use the Fill Handle icon to copy the formula into other cells of Column D.
- Similarly, use Fill Handle to copy the formula in Cell E5 to other cells of Column E.
2. Combining ARRAYFORMULA and TRIM Functions
We can apply a combination of the ARRAYFORMULA function and the TRIM function to remove additional spaces from the texts of an array. It will save time because it will return all the output directly as an array. For that, we have taken the following dataset.
- First, select Cell D5 and then type in the following formula. After that, press the Enter key to see the output.
Now see, we got all the output at a time.
First, the TRIM function removes the leading, trailing, or repeated spaces for every text value of the array B5:C7.
After that, the ARRAYFORMULA function will help to display the trimmed array.
3. Merging ARRAYFORMULA, TRIM, and SPLIT Functions
We often use the SPLIT function for splitting multiple options from a single cell to multiple cells in a row. But the leading space used between the options of a single cell remains. Therefore, we can merge the ARRAYFORMULA and TRIM functions with the SPLIT function to remove these leading spaces. The dataset for this method is as follows:
- First, select Cell C5 and then type in the following formula. Finally, press the Enter key to see the output.
At the beginning of execution, the SPLIT function will divide the input texts from a cell into fragments around the Comma (,) symbol and then puts them in cells of a row.
After that, the TRIM function removes additional leading space from each fragmented text returned by the SPLIT function.
In the end, the ARRAYFORMULA function helps with displaying the array.
4. Joining ARRAYFORMULA, TRIM, FLATTEN and SPLIT Functions
We can show the output of method 3 in a single column by joining the FLATTEN function with the previously used ARRAYFORMULA, TRIM, and SPLIT functions. Here is the dataset required for this method.
- First, select Cell C5 and then type in the following formula. After that press Enter key to view the output-
First, the SPLIT function divides the texts in array B5:B6 around the Comma (,) symbol and then puts them in different cells in a row.
Then, the FLATTEN function puts the values returned by the SPLIT function into a column.
After that, the TRIM function removes the leading spaces from the text values.
Finally, the ARRAYFORMULA function helps with displaying the output array.
- Here, Cell B5 has 3 values, whereas Cell B6 has 4 values. The FLATTEN function takes the maximum value of 4 and shows the values as a set of 4 entries in a column. That’s why Cell C8 is empty.
Alternate of TRIM Function in Google Sheets
An alternative to using the TRIM function is to use the Trim Whitespace option from the Data ribbon. We’ll be using the following dataset for this alternate method.
- First, select the array B5:B10 and then go to the Data ribbon. Then from the Data Cleanup option, click on Trim Whitespace.
- A window like the following will pop out. Click on OK.
- The additional spaces in selected cells have now been removed and it is also evident from the change in text length.
This ends our article on learning how to use the TRIM function in Google Sheets. I hope the demonstrated methods and examples will satisfy your requirements. Feel free to leave your thoughts on the article in the comment box.