WPS Office

Free All-in-One Office Suite with PDF Editor

correct-icon

Edit Word, Excel, and PPT for FREE.

correct-icon

Read, edit, and convert PDFs with the powerful PDF toolkit.

correct-icon

Microsoft-like interface, easy to use.

Free download

Windows • MacOS • Linux • iOS • Android

banner

The TRIM Function in Excel

August 24, 2023
8.2K Views

Want to Learn Excel? Here is a WPS Spreadsheet online training that will teach you all the basics and advanced skills. Download WPS Office, easily find more about spreadsheet formulas, data, and cells in WPS professional spreadsheet tutorials.

What is the TRIM formula in Excel?

TRIM formula in Excel


The TRIM formula in Excel is a built-in function designed to clean up text by removing any leading and trailing spaces from a cell's content. It's an essential tool for data cleaning, ensuring consistency, and maintaining accurate analyses. This function is particularly useful when dealing with imported data, user inputs, or text manipulation tasks where unwanted spaces might cause formatting issues.

· Description:

The TRIM function removes the leading and trailing spaces and the unnecessary spaces between words. When receiving the text with irregular spacing, you can use TRIM to modify quickly and easily.

· Syntax:

=TRIM(text)

· Arguments:

Text: The text to remove the unnecessary spaces from.

When is the TRIM function beneficial in Excel?

The TRIM function in Excel is particularly beneficial in scenarios where text data requires cleaning, consistency, and accurate representation. Here are a few common situations where the TRIM function proves its worth:

  • Data Copy-Pasting: When you copy data from external sources like websites, databases, or other spreadsheets, it often comes with hidden characters, extra spaces, or tabs. Applying the TRIM function to such data ensures that unnecessary characters are removed, making it easier to work with and preventing errors caused by hidden formatting.

  • Cleaning Up Data: Data imports and user inputs can sometimes introduce unwanted spaces in the text. These spaces might not be immediately visible, but they can lead to inconsistencies and errors in analyses. The TRIM function cleans up leading, trailing, and excessive spaces, ensuring that your data remains accurate and reliable.

  • Comparing Text: Comparing or sorting text data might yield unexpected results due to hidden spaces. Even seemingly identical strings can be distinct if they contain extra spaces. By using the TRIM function, you eliminate these hidden discrepancies, allowing for accurate comparisons and reliable sorting.

  • Formatting Issues: Text formatting in Excel, such as alignment and wrapping, can be compromised by extra spaces. These spaces might disrupt the visual layout and presentation of your data. The TRIM function helps maintain proper formatting by removing unnecessary spaces and ensuring that your text appears as intended.

  • Counting Characters: Counting characters in a cell is a common task, but extra spaces can skew the results. By applying the TRIM function, you can accurately count the visible characters in a cell without considering the hidden spaces. This ensures precise character counts for analysis and reporting.

In essence, the TRIM function serves as a valuable tool for maintaining the quality, accuracy, and consistency of text data within Excel. It streamlines data preparation, enhances data integrity, and aids in performing more accurate calculations and analyses. Whether you're working with large datasets, collaborating on spreadsheets, or simply striving for cleaner data representation, the TRIM function is your go-to solution.

How to Use the TRIM Function in Excel

Using the TRIM function in Excel is straightforward and can significantly enhance the quality of your text data. Let's walk through a step-by-step guide using a commonly encountered example.

Suppose you have a list of names in column A, but some of the names have unwanted spaces at the beginning or end. You want to clean up this list using the TRIM function.

Step 1: Open Excel and Load Your Data

Open Microsoft Excel and load the spreadsheet containing the data you want to clean. In this example, we have a list of names in column A.

Uncleaned data in Excel


Step 2: Select a Cell for Cleaned Data

In a new column (let's say column B), select the cell where you want the cleaned data to appear. In this case, we'll use cell B2.

Step 3: Enter the TRIM Formula

In the selected cell (B2), enter the TRIM formula. Type =TRIM(A2) in the cell. This formula tells Excel to clean up the text in cell A2 by removing any leading or trailing spaces.

TRIM function to clean the data in Excel


Step 4: Press Enter and Apply the Formula

After typing the formula, press the Enter key. Excel will apply the TRIM function to the text in cell A2 and display the cleaned-up result in cell B2.

cleaned data in Excel


Step 5: Autofill for the Entire List

To clean up the entire list of names, use the autofill handle in the bottom right corner of cell B2. Click and drag the handle down to fill the formula for all the names in column A. Excel will automatically apply the TRIM function to each corresponding cell in column A and populate column B with cleaned data.

cleaned data with TRIM function in Excel


Step 6: Review and Enjoy Cleaned Data

Now, column B contains the cleaned-up names without any leading or trailing spaces. Review the results and enjoy your data in a cleaner, more consistent format.

Excel TRIM Function – Examples

Understanding the Excel TRIM function through practical examples can provide valuable insights into its usefulness and versatility. Let's explore three scenarios where the TRIM function comes to the rescue.

Example 1 – Remove Leading, Trailing, and Double Spaces

In this example, we'll tackle a common issue: dealing with leading, trailing, and double spaces within cells.

Leading, Trailing, and Double Spaces in Excel


To clean up this data set and remove all the extra spaces, use the following TRIM function:

=TRIM(A1)

Remove Leading, Trailing, and Double Spaces in Excel


By applying this formula to each cell, you'll effectively remove the leading, trailing, and double spaces, resulting in clean and consistent text.

Removing Leading, Trailing, and Double Spaces in Excel

Example 2 – Remove Leading Spaces Only

In some cases, you might want to eliminate only the leading spaces while preserving intentional formatting.

Remove Leading Spaces in Excel


In this dataset, we want to remove only the leading spaces without altering the intentional double spaces. To achieve this, you can use the following formula:

=RIGHT(A1,LEN(A1)-FIND(MID(TRIM(A1),1,1),A1)+1)

Removed Leading Spaces in Excel


This formula calculates the position of the first non-space character and then extracts the text from that position onward, effectively removing only the leading spaces.

Removed Leading Spaces in Excel

What to Do When Excel's TRIM Function Doesn't Work

While Excel's TRIM function is a handy tool for cleaning up text, there might be instances when it doesn't work as expected. This can happen due to various reasons, such as non-breaking spaces, non-printable characters, or other anomalies in the text. If you find that the TRIM function isn't delivering the desired results, here's what you can do to troubleshoot and solve the issue.

Using CLEAN Function

The CLEAN function is your ally when you encounter non-printable characters that the TRIM function can't handle. Non-printable characters are often unseen but can cause formatting and processing issues.

Syntax:

=CLEAN(text)

Scenario: Let's say you have the following text with non-printable characters in cell C5:

Solution: To remove these non-printable characters, use the CLEAN function like this:

=CLEAN(C5)

Remove non-printable characters in Excel


The CLEAN function will swiftly eliminate those tricky characters, leaving you with clean and printable text.

non-printable characters in Excel

Using SUBSTITUTE Function

The SUBSTITUTE function comes to the rescue when you need to replace specific characters with others. It's ideal for dealing with non-printable characters that might be causing issues.

Syntax:

=SUBSTITUTE(text, old_text, new_text)

Scenario: Let's consider a case where you have non-printable characters in cell C5:

SUBSTITUTE function in Excel


Solution: To replace these non-printable characters with spaces, use the SUBSTITUTE function as follows:

=SUBSTITUTE(C5, CHAR11), " ")

In this example, CHAR(11) represents the non-printable character. The SUBSTITUTE function swaps these characters with spaces, allowing your text to appear as desired.

Type the specific character numbers inside the formula (CHAR(7), CHAR(12), etc.), one at a time, and then press ENTER. The end result will resemble the image below.

Use of SUBSTITUTE function in Excel

Free Alternative – WPS Office

WPS Office


WPS Office is a versatile and free office suite that offers a comprehensive set of tools for opening, creating, editing, and saving Microsoft Office files. Whether you're working with Word documents, Excel spreadsheets, or PowerPoint presentations, WPS Office provides a seamless and fully compatible experience on both Windows and Mac platforms.

Features of WPS Office

WPS Office boasts a range of features designed to enhance your productivity and streamline your work processes. Here's a brief introduction to some of its key features:

  1. Word Processing: WPS Writer is the word processing component of the suite. It provides a user-friendly interface for creating and editing documents, offering a variety of formatting options, templates, and collaboration tools.

  2. Spreadsheet Capabilities: With WPS Spreadsheets, you can handle data and calculations efficiently. This component supports a wide range of functions, formulas, and formatting features, making it suitable for various business and personal tasks.

  3. Dynamic Presentations: WPS Presentation empowers you to craft engaging slideshows. You can create visually appealing presentations using various templates, animations, and multimedia elements.

  4. PDF Editing: WPS Office allows you to directly edit PDF documents, enabling you to modify text, images, and other content without the need for additional software.

  5. Compatibility: WPS Office maintains a high level of compatibility with Microsoft Office formats, ensuring smooth document exchange and collaboration with users who use the Microsoft Office suite.

Here are the steps to edit Word, Excel, and PowerPoint documents in WPS Office:

Editing Word Documents in WPS Office:

  1. Open WPS Writer: Launch WPS Office and click on the "Writer" icon to open the word processing component.

  2. Open the Document: Go to "File" in the top menu and select "Open." Browse your computer for the Word document you want to edit and click "Open."

  3. Edit the Document: Make your desired changes to the document. You can modify text, formatting, insert images, tables, and more.

  4. Save Changes: After editing, click on the "File" menu again and choose "Save" or "Save As" if you want to save a copy with changes. Select the location to save the document and click "Save."

Editing Excel Spreadsheets in WPS Office:

  1. Launch WPS Spreadsheets: Open WPS Office and click on the "Spreadsheets" icon to access the spreadsheet component.

  2. Open the Spreadsheet: Navigate to "File" in the top menu and choose "Open." Locate the Excel spreadsheet you want to edit and click "Open."

  3. Edit the Spreadsheet: Make necessary changes to the spreadsheet. You can update cell values, formulas, formatting, and more.

  4. Save Changes: When done editing, click on the "File" menu and select "Save" or "Save As" to save your changes. Choose the location to save the modified spreadsheet and click "Save."

Editing PowerPoint Presentations in WPS Office:

  1. Open WPS Presentation: Launch WPS Office and click on the "Presentation" icon to open the presentation component.

  2. Open the Presentation: Click on "File" in the top menu and pick "Open." Browse your computer for the PowerPoint presentation you wish to edit and click "Open."

  3. Edit the Presentation: Modify the slides by adding or updating content, images, animations, and more.

  4. Save Changes: After making edits, go to the "File" menu and select "Save" or "Save As" if you want to save a revised copy. Indicate the location to save the presentation and click "Save."

    Trustpilotstars4.8
    WPS Office- Free All-in-One Office Suite
    5,820,008 User
    avator
    Algirdas Jasaitis
    logo
  • Use Word, Excel, and PPT for FREE, No Ads.

  • Edit PDF files with the powerful PDF toolkit.

  • Microsoft-like interface. Easy to learn. 100% Compatibility.

  • Boost your productivity with WPS's abundant free Word, Excel, PPT, and CV templates.

FAQs

1. Can TRIM be used to clean up data in multiple cells at once?

Yes, the TRIM function can be used to clean up data in multiple cells simultaneously. When applied to a range of cells, it will remove leading and trailing spaces from the text within each cell. If you're dealing with a dataset with multiple cells containing extra spaces, applying TRIM to the entire range can quickly clean up the data and make it more consistent.

2. Does TRIM remove spaces between numbers in a cell?

No, the TRIM function doesn't remove spaces between numbers within a cell. The primary purpose of the TRIM function is to remove leading and trailing spaces from text, not spaces between words or characters. If you have spaces between numbers within a cell and you want to remove them, you might need to use a different approach, such as using the SUBSTITUTE function to replace those spaces with nothing.

Conclusion: Using TRIM Function in Excel

In a world where efficient document processing is crucial, WPS Office emerges as a compelling and free alternative to meet your diverse office needs. This versatile suite, compatible with both Windows and Mac platforms, proves its mettle by offering a seamless experience for working with Microsoft Word, Excel, and PowerPoint files. From cleaning up and formatting text data using the TRIM function to exploring advanced features like PDF editing, WPS Office caters to a wide array of tasks, simplifying the complexities of office work.


15 years of office industry experience, tech lover and copywriter. Follow me for product reviews, comparisons, and recommendations for new apps and software.