Over 2 million + professionals use CFI to learn accounting, financial analysis, modeling and more. Unlock the essentials of corporate finance with our free resources and get an exclusive sneak peek at the first module of each course.
Start Free
The TRIM function in Excel removes extra spaces from text, leaving only single spaces between words. It cleans up data by eliminating leading, trailing, and intervening spaces, useful for data imported from other sources. The function uses the formula =TRIM(text) and only removes ASCII space characters. TRIM is essential for text normalization but does not affect non-breaking spaces (Unicode 160). It is particularly helpful in financial analysis for cleaning irregularly spaced 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.
Key Highlights
The TRIM function in Excel eliminates extra space in data, helping clean up the cells in the worksheet.
It removes leading, trailing, and intervening spaces, leaving only a single space character between words and no space characters at the start or end of text.
TRIM only removes the ASCII space character (32) from the text.
Formula for the TRIM Function
=TRIM(text)
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:
For trimming the spaces, we will use the following function:
We get the results below:
Example 2
Let us see how the TRIM function works for numbers. Suppose we are the given the data below:
The formula to use is:
Using the TRIM function, we will get the following result:
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:
The above formula removes all leading and trailing spaces, if any, and turns the resulting value into a number, as shown below:
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:
The formula to use is:
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.
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:
To master the art of Excel, check out CFI’s Excel Crash Course, which teaches you how to become an Excel power user. Learn the most important formulas, functions, and shortcuts to become confident in your financial analysis.
Take your learning and productivity to the next level with our Premium Templates.
Upgrading to a paid membership gives you access to our extensive collection of plug-and-play Templates designed to power your performance—as well as CFI's full course catalog and accredited Certification Programs.
Gain unlimited access to more than 250 productivity Templates, CFI's full course catalog and accredited Certification Programs, hundreds of resources, expert reviews and support, the chance to work with real-world finance and research tools, and more.