Excel’s TRIM Function [inc 2 Examples & Troubleshooting]

 

The TRIM Function in Excel is useful for removing extra spaces from text.

It’s especially handy when cleaning data imported from other sources.

TRIM Function Details

Trim Function in action

Available in: All versions of Microsoft Excel
User Level: Beginners
Inputs: “Text”: The text string from which you want to remove spaces.
Output: Text string without extra spaces. Data Type: Text
Wildcards: No
Case Sensitive: No

Where To Find The TRIM Function

To find the TRIM function, go to the top of the ribbon on your screen.

Click Formulas > Text, and scroll down to the TRIM function button.

The Text dropdown in Excel, where the TRIM function is found

The TRIM function in the dropdown menu

Not the function you are looking for?

Using TRIM With Other Data Types

Table of TRIMs outputs when using other data types

Currency data:

Currency is treated as a number in Excel.

Format currency as text to use TRIM effectively.

All other data types should work as intended with TRIM.

If you have any issues, reformat the data type as text!

Simple Example

Imagine you have a list of names with inconsistent spacing.

Use TRIM to clean it up. In cell A2, type

=TRIM(A2)

This removes extra spaces from the name in A2.

Screenshot giving an example of how the formula works

Learning to clean data is the first step to mastering data analysis, all part of our advanced Excel courses.

Advanced Example

Let’s try combining TRIM with the SUBSTITUTE function.

Suppose you want to remove all spaces, not just extra ones.

In cell B1, type

=SUBSTITUTE(TRIM(A2), " ", "")

This first trims A1, then removes all remaining spaces.

Screenshot of Excel giving a more complex example of how the formula works

Combining functions together is a great way to increase the complexity of your work.

The TRIM function can also be combined with the CONCATENATE function to combine text from different cells!

excel-promo-1

Troubleshooting & Errors

Let’s take a look at the most common errors you will get when working with the TRIM function.

Error 1: #VALUE! Error

Cause: Non-text input.

Solution: Ensure the input is a text string.

Error 2: No Change in Data

Cause: No extra spaces in the input.

Solution: Check if the data already has the correct spacing.

Mastering Excel’s formula auditing tools will you fix any error codes you may come across.

What Is The TRIM Function Useful For?

The TRIM function is perfect for formatting big sets of data quickly. This makes it very useful in some key areas.

1. Data Cleaning Removes unnecessary spaces, ensuring data consistency.
2. Data Validation Helps in verifying and correcting text data.
3. Preparing Data for Analysis Cleans data for accurate statistical analysis.

Once data has been cleaned, you can use the FIND Function to search through it without issues.

Similar Useful Functions

Other functions similar to the Excel value function that are easy to use include:

  • TEXT: Converts numbers into text.
  • FORMAT: Returns a fully formatted string based on conditions.
  • TIME: Lets you create a time with specific components.

Conclusion:

The TRIM function in Excel is a simple yet powerful tool for maintaining data integrity.

It’s essential for cleaning and preparing text data, making it a valuable skill for anyone using Excel.

About Ben Richardson

Ben is a director of Acuity Training which he has been running for over 10 years.


He is a Natural Sciences graduate from the University of Cambridge and a qualified accountant with the ICAEW.


He previously worked as a venture capitalist and banker and so had extensive experience with Excel from building financial models before moving to learn SQL, Microsoft Power BI and other technologies more recently.