Back to Blog

LEN and TRIM Functions in Excel: Complete Guide with Examples | SheetXAI

D
David DeSouza
Dec 1, 2025
Vector illustration showing two figures interacting with a dual-panel calendar, representing text length measurement and space trimming operations in spreadsheets

The Problem

You have text in column A with extra spaces that need to be cleaned up, or you need to know how long each text string is. Some cells have leading/trailing spaces that cause issues.

The Easy Way: Use SheetXAI

If you don't want to mess with formulas, the fastest way to do this is simply by asking.

With SheetXAI, you can open the sidebar and type:

Remove all extra spaces from the text in A2 and tell me how many characters it has.

SheetXAI will instantly write the formula or script for you and fill the cells. It handles the syntax so you can focus on the result.

The Manual Way: The Formulas You Need

To do this manually, you need to use: LEN and TRIM.

1. LEN

Returns the number of characters in a text string, including spaces.

Syntax: =LEN(text)

  • text: The text string you want to measure the length of.

Example: LEN('Hello World') returns 11 (including the space).

2. TRIM

Removes all spaces from text except for single spaces between words. Removes leading spaces, trailing spaces, and extra spaces between words.

Syntax: =TRIM(text)

  • text: The text string you want to clean up.

Example: TRIM(' Hello World ') returns 'Hello World' (removes extra spaces).

Understanding the Logic

  1. LEN: Counts all characters including spaces. Useful for data validation, finding text of specific lengths, or combining with other functions.
  2. TRIM: Cleans up text by removing leading, trailing, and extra spaces. Essential for data cleaning before comparisons or lookups.

Common combinations:

  • Use TRIM to clean data, then LEN to verify the cleaned length
  • Combine TRIM with other text functions for data cleaning workflows
  • Use LEN to validate text length (e.g., phone numbers, IDs)
  • TRIM is often used before VLOOKUP or other lookup functions to ensure matches work correctly

The Final Formula:

=TRIM(A2)

Conclusion

Now you know the "classic" way to solve this using formulas. It's a great skill to have.

But for those times when you just want the job done without the mental math, SheetXAI is there to help.

Boost your productivity today.
Start automating your spreadsheets.

Join thousands of professionals saving hours every week. No credit card required to start.

Learn more