A big part of cleaning up data is removing spaces in cells with text. Usually, these spaces are imported when text is copied or pasted in Excel. Luckily, there is an easy function that you can use to remove leading and trailing spaces in cells with text. This function is called TRIM.
How to Remove Leading and Trailing Spaces
The Trim function eliminates spaces from text in an Excel cell. This function can also remove spaces between spaces in newer versions of Excel. For example, let’s evaluate how it removes leading and trailing spaces.; the word “character” has spaces before and after the word in the first to examples. Using TRIM(text) will clean the spaces from the text.
Using the trim function will help you eliminate the spaces. Simply type = TRIM and enter your cell reference. See the example below:
Trim also allows you to remove spaces in the middle of text
The trim function can also remove text in the middle of your text string. See the image below for a quick demonstration.
What do you do when you have broken line text?
When you have a broken line. You can also use TRIM to eliminate unwanted spaces in cells.