MySheetAI
ProductWhat you can askPricing
Sign inAsk your data
MySheetAI
ProductWhat you can askPricingFormula generatorBlogChangelogFAQContactPrivacyTerms
© 2026 MySheetAI. All rights reserved.
Answers/How to Remove Extra Spaces and Hidden Characters with TRIM and CLEAN

How do I remove extra spaces or hidden characters from text I pasted into a spreadsheet?

TRIM removes leading, trailing, and repeated internal spaces from text, and CLEAN removes nonprintable characters that often come along with data pasted from another system: =TRIM(CLEAN(A2)). Use both together on data you did not type yourself.

Formula (Excel and Google Sheets)

=TRIM(CLEAN(A2))

TRIM cleans up spacing: it removes any spaces at the very start or end of the text, and collapses multiple spaces in a row down to a single space. This matters because "Acme Inc" and "Acme Inc " (with a trailing space) look identical to a person but count as two different values to a formula, breaking lookups, COUNTIF, and grouped totals.

CLEAN removes a different kind of problem: nonprintable characters (leftover line breaks or control codes) that sometimes come in when data is pasted from a website, a PDF, or another system. These characters are often invisible but still count as part of the text, so a value can look identical to another and still fail to match. Wrapping CLEAN around TRIM (or the other way around) handles both problems in one formula.

Step by step

  1. 1

    Add a helper column next to the messy data

    Do not overwrite the original column yet, in case you need to check your work.

  2. 2

    Enter =TRIM(CLEAN(A2))

    Referencing the cell with the pasted or imported text.

  3. 3

    Copy the formula down, then paste values over the original column

    Once you have checked the cleaned column looks right, copy it and paste as values over (or in place of) the original.

Common questions

Why do two cells that look identical fail to match in a lookup?

One usually has a trailing space, a leading space, or a hidden nonprintable character the other does not. TRIM and CLEAN remove both kinds of difference.

Does TRIM remove all spaces, including the ones I want?

No. TRIM keeps single spaces between words; it only removes leading, trailing, and extra repeated spaces, not normal single-space gaps.

Related formulas

Related

How to Remove Duplicate Rows in Excel and Google Sheets

Related

How to Format Text and Dates with the TEXT Formula

Related

How to Combine Text from Multiple Cells with CONCATENATE and TEXTJOIN

From the blog

How to Make Sense of Your Spreadsheet Data Without Being an Analyst

Want a formula written for your exact spreadsheet, not a generic example?

Try the free formula generator