To clean text in Excel with LEN and TRIM, use TRIM to remove extra spaces and LEN to count characters. The quickest working combo is =TRIM(A1) to clean a cell and =LEN(TRIM(A1)) to see the cleaned length. This guide shows exact steps, common mistakes, and fixes so you can tidy names, addresses, and imported data without guesswork.

What You'll Need

  • Excel for Windows, Mac, or Excel for the web (desktop recommended for full features).
  • Data in a worksheet, ideally with a header row.
  • Basic familiarity with entering formulas and copying them down a column.

Step-by-Step

  1. Open your workbook and inspect the data. Click a cell that looks messy. Look at the formula bar to see leading, trailing, or double spaces. TRIM removes these; LEN counts every character including spaces, so you can compare before and after.
  2. Create a helper column. In the first empty column to the right of your data, click the header cell (for example B1) and type Cleaned. This keeps your original data intact.
  3. Enter the TRIM formula. In B2, type =TRIM(A2) and press Enter. This returns the text with extra spaces removed, leaving single spaces between words.
  4. Copy the formula down. Select B2, double-click the fill handle (the small square at the bottom-right corner of the cell) or drag it down to the last row. Every row now has a cleaned version.
  5. Check the cleaned length with LEN. In C1 type Length. In C2 type =LEN(B2) and press Enter. This counts characters in the cleaned text. To compare with the original, in D2 type =LEN(A2). The difference shows how many spaces TRIM removed.
  6. Use the combined formula if you prefer one step. In B2 you can type =LEN(TRIM(A2)) to get the cleaned length directly. This is handy when you only need the count, not the cleaned text.
  7. Convert formulas to values (optional). If you want to delete the original column, first copy the cleaned column, then right-click and choose Paste Special > Values over the same range. This replaces formulas with plain text so they no longer depend on column A.
  8. Verify a few rows manually. Click a cleaned cell and compare it to the original in the formula bar. Check that internal single spaces remain and only extra spaces are gone.

Menu labels and dialog wording can differ slightly by Excel version, device, and region. On Excel for the web, the same formulas work; the fill handle and Paste Special options are in the same places but may appear slightly differently.

Common Mistakes

  • Expecting TRIM to remove all spaces. TRIM removes leading, trailing, and repeated spaces between words, but it leaves a single space between words. It does not remove non-breaking spaces (character 160) that often come from web pages. Use =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) to convert those first.
  • Forgetting that LEN counts spaces. A cell that looks empty may contain a space, so =LEN(A2) returns 1, not 0. This is a common cause of lookup failures.
  • Overwriting original data. Always work in a helper column until you have verified the results. Pasting values over the original column is irreversible without undo.
  • Using TRIM on numbers. TRIM returns text, so a number becomes text and may no longer calculate. Use it only on text fields, or convert back with =VALUE(TRIM(A2)) if needed.
  • Assuming TRIM fixes line breaks. TRIM does not remove line breaks (character 10). Use =CLEAN(A2) to remove non-printing characters, then TRIM.

Tips

  • Use =LEN(A2)-LEN(TRIM(A2)) to count exactly how many extra spaces were removed from a cell.
  • Combine CLEAN and TRIM: =TRIM(CLEAN(A2)) handles both non-printing characters and extra spaces in one formula.
  • Apply TRIM before comparing or matching text in VLOOKUP or XLOOKUP; trailing spaces are a frequent cause of #N/A errors.
  • If you need to clean an entire column permanently, copy the cleaned column, then use Paste Special > Values over the original, and delete the helper column.
  • For a quick visual check, use conditional formatting to highlight cells where =LEN(A2)<>LEN(TRIM(A2)) is true.

Troubleshooting

If TRIM does not seem to work, first check for non-breaking spaces. Select the cell, look at the formula bar, and try =LEN(A2) versus =LEN(TRIM(A2)). If the lengths are equal but the text still looks spaced, the spaces are likely non-breaking. Use SUBSTITUTE as shown above.

If LEN returns an error, confirm the cell reference is correct and that the cell contains text, not an error value. If the formula shows as text instead of calculating, the cell may be formatted as Text; change the format to General and re-enter the formula.

If copying the formula down does not update references, check that you used relative references (A2, not $A$2). Press F2 then Enter to force a recalculation. If calculation is set to Manual, go to Formulas > Calculation Options and choose Automatic.

If Paste Special > Values is greyed out, make sure you copied the range first and that the worksheet is not protected. Unprotect via Review > Unprotect Sheet if you have the password.

Frequently Asked Questions

What is the difference between LEN and TRIM?

LEN counts the number of characters in a cell, including spaces. TRIM removes extra spaces from text, leaving single spaces between words. They are often used together: =LEN(TRIM(A2)) gives the length after cleaning.

Does TRIM remove all spaces?

No. TRIM removes leading, trailing, and repeated spaces between words, but it keeps a single space between words. It does not remove non-breaking spaces; use SUBSTITUTE with CHAR(160) for those.

Can I use LEN and TRIM on numbers?

Yes, but both return text. If you need the numeric value after trimming, wrap with VALUE: =VALUE(TRIM(A2)). Be aware that numbers with leading zeros will lose them when converted.

Why does LEN show a different number than I expect?

LEN counts every character, including spaces and non-printing characters. A cell that looks empty may contain a space, returning 1. Use =LEN(TRIM(A2)) to see the length after removing extra spaces.

Does TRIM work in Excel for the web and Google Sheets?

Yes, TRIM and LEN are standard functions in Excel for the web and Google Sheets. The formulas are the same, though menu locations for Paste Special may differ.

How do I remove line breaks with TRIM?

TRIM does not remove line breaks. Use CLEAN to remove non-printing characters, then TRIM: =TRIM(CLEAN(A2)). This handles both line breaks and extra spaces.