EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • All Courses
    • All Specializations
  • Blog
  • Enterprise
  • Free Courses
  • All Courses
  • All Specializations
  • Log in
  • Sign Up
Home Excel Excel Resources TEXT and String Functions in Excel Excel TRIM Function
 

Excel TRIM Function

Madhuri Thakur
Article byMadhuri Thakur

Updated July 5, 2023

TRIM in Excel

 

 

TRIM in Excel

The trim in Excel removes the extra spaces from the start and end of the cell value. This is useful when we have the same values in a column, but some cells contain extra spaces. By this Trim function, we can remove the extra spaces from any cell, irrespective of the number of spaces in that selected cell.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

TRIM Formula in Excel

Below is the TRIM Formula in Excel:

TRIM Formula in Excel

Trim function arguments

There is only one argument in the Trim function, which is below mention.

=Text(Cell Value / Text)

Shortcut of using the formula

Click on the cell where you want to result in value, then put the formula as below mentioned

= Trim(Cell Value / Text)

Steps for using the Trim function in Excel

  • Click on the formula tab > Text > click on Trim

Step 1

  • Also, click on the function icon, then manually write and search the formula.

Step 2

  • We get a new function window shown below, mention in the pictures.

Step 3

  • Then we have to enter the details as shown in the picture.

Put the Cell or text values where you want to remove space from data.

Step 4

  • Then Click On OK.

Step 5

  • The result is:

Step 6

How to Use the TRIM Function in Excel?

Trim Function in Excel is very simple and easy to use. Let us now see how to use the TRIM function in Excel with the help of some examples.

You can download this TRIM Function Excel Template here – TRIM Function Excel Template

Example #1

Suppose we have a column of customer names that have some space before and after the text and more than one space between the words. So, how do we remove all extra space in a cell at a time on overall data by copying an Excel TRIM formula across the column and then replacing formulas with their values? Let’s start to write the formula; the detailed steps are mentioned below:

Example 1-1

  • Write a TRIM formula for the first-row cell, A2, in our example:

=TRIM(A2)

TRIM Function Example 1-2

The Result is:

TRIM Example 1-3

  • A position of the cursor to the lower right corner of the formula cell (B2 in this example),

TRIM Example 1-4

  • Select the range (B2:B12) and fill the formula to the last cell with data.

TRIM Example 1-5

  • As a result, you will have 2 columns of original names with spaces and formula-trimmed customers’ names.

TRIM Example 1-6

Now, replace the values in the original column with the trimmed data value, But be careful. Simply copy and paste the trimmed column data value over the original column; otherwise, destroy your formulas, and we also lose the data. So such a type of this happens. You need to copy only values, not formulas. The steps are below mention.

  • Select all cells with Trim formulas (B2:B12 in this example), and copy (CTRL+C) the selected range.

TRIM Example 1-7

  • Select all cells with the original data (A2:A12)

TRIM Example 1-8

  • And Paste the data as value only, not a formula; you can also use a shortcut method for paste special (Ctrl+Alt+V). The dialog box will appear.

TRIM Example 1-9

  • Then again, V is for value.

TRIM Example 1-10

  • Press the Enter, and the result will look like

Result of Example 1-11

Example #2

Normally when we fetch data in Excel from another application or any database like SQL Server, Oracle, or HTML, we face such type issue for line breaking with extra space; we can say that double line issue or wrap text issue, and also ever include with a special character which is not removed with only trim. So we can use a trim function with a clean function for such type situations. The example is shown below:

Example 2-1

So now we can use a trim function with a clean function.

  • Write the formula =TRIM(CLEAN(A16))

TRIM Function Example 2-2

The result is :

TRIM Example 2-3

  • The cursor is position in the lower right corner of the formula cell (B16 in this example)

TRIM Example 2-4

  • Select the range and fill down the column with the formula.

TRIM Example 2-5

The result is:

TRIM Example 2-6

  • Then you need to copy and paste values only, not formulas like in the first example.

Result of Example 2-7

Explanation of the TRIM Function in Excel

Before removing spaces in data, if we want to know how much extra space or total space is in the Excel sheet, we get the LEN function’s help with a trim function. If you want to get the total number of extra spaces in a cell, then, first of all, we find the total number of text lengths using the Len function, then calculate the string length without extra spaces and subtract the latter from the total length. The formula is as showing below

=LEN(A16)-LEN(TRIM(A16))

The following screenshot shows the above formula in action:

TRIM Example 3-1

The result is:

TRIM Example 3-2

Note: This function returns the count of extra spaces in a cell, but this function will not be useful as we want to count with a single space or spaces in the middle of text because trim removed only the unwanted spaces. We can use a substitute formula with the LEN function to get the total number of spaces in a cell.

As I remember above, we have used the trim function with a LEN function for extra space count. The same activity we are doing here for total spaces count uses the LEN function with a substitute function. The substitute function replaces old text as a new value; in the example below, we substrates the only text value from the total length count; thus, we found a total no of spaces.

=LEN(A16)-LEN(SUBSTITUTE(A16,” “,””))

TRIM Example 4-1

The result is:

TRIM Example 4-2

Things to Remember

  • TRIM will remove extra spaces from the text. Thus, it will leave only single spaces between words and no space characters at the start or end of the text.
  • The TRIM function was designed to trim the 7-bit ASCII space character (value 32) from the text, so it only removes the ASCII space character (32) from the text.
  • The TRIM function will not remove non-breaking space characters commonly used in HTML web pages.
  • The Unicode text often contains a non-breaking space character (160) that appears on web pages as an HTML entity. It will not be removed with TRIM.

Recommended Articles

This has been a guide to TRIM in Excel. Here we discuss the TRIM Formula and how to use the TRIM function in Excel, along with practical examples and a downloadable Excel template. You can also go through our other suggested articles –

  1. Left TRIM in Excel
  2. Excel Evaluate Formula
  3. VBA TRIM
  4. Excel Column Total
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA
Free Excel Course

Excel functions, formula, charts, formatting creating excel dashboard & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

Download TRIM Function Excel Template

EDUCBA Login

Forgot Password?

EDUCBA

Download TRIM Function Excel Template

EDUCBA

डाउनलोड TRIM Function Excel Template

🚀 Limited Time Offer! - 🎁 ENROLL NOW