In Excel: use =TRIM(text) — it removes leading and trailing spaces and collapses every run of internal spaces down to a single space.
On this page8
Syntax
Arguments
| Argument | required / optional | Description |
|---|---|---|
text | required | The text or cell to clean of extra spaces. |
Related functions
In an empty helper cell type =TRIM( and click the cell with the messy text, such as A2.
Close the bracket and press Enter to see the cleaned value.
Fill the formula down the column to clean every row.
If spaces remain, wrap it to strip non-breaking spaces: =TRIM(SUBSTITUTE(A2, CHAR(160), " ")).
Copy the helper column and Paste Special as Values over the original if you want to replace the raw text.
What this does
TRIM tidies up text by stripping spaces from the start and end of a value and reducing any stretch of multiple spaces between words to one. It is the standard fix for data pasted from other systems, where stray spaces break lookups and sorts. The important caveat is that TRIM only removes the ordinary space character (CHAR(32)); it does NOT remove the non-breaking space CHAR(160) that often arrives when you paste from web pages or PDFs — for that you need SUBSTITUTE to replace CHAR(160) with an ordinary space before TRIM. CLEAN removes control characters with codes 0–31; it does not remove CHAR(160). Keep the inputs visible and clearly labelled and the whole thing stays auditable — anyone who opens the file later, including you, can see at a glance exactly what feeds the result and change one assumption without hunting through the formula. For “trim function in excel”, the reliable version is a short checking loop, not just the first command that appears to work. Run it on a deliberately small range first, watch how the affected formula change, and only then apply the same setup to the full sheet. When a formula is involved, keep the inputs labelled beside it, reference cells instead of typing values, and apply number formatting only after the result checks out. That is what makes a text operation that turns messy entries into clean, usable data useful in real work: repeatable, auditable, and not dependent on memory or luck.
A worked example
Cell A2 holds " John Smith " with a leading space, two spaces between the names, and a trailing space. =TRIM(A2) returns "John Smith" — the outer spaces are gone and the double space is collapsed to one. If A2 came from a web page and still looks untrimmed, a non-breaking space is hiding in it; clean it first with =TRIM(SUBSTITUTE(A2, CHAR(160), " ")). TRIM is the first cleanup step before lookups, sorts and matches, where invisible leading, trailing or doubled spaces silently cause mismatches and #N/A errors. Check the referenced cells, argument order and result type in your workbook. Start with the worked example before changing an input, then compare the changed result with the calculation you expected. An error value or a result of a different type is a reason to inspect the inputs and arguments.
In Google Sheets
The standard worksheet functions used by this example are listed in Google Sheets. Check the cell references, argument separators and input types in the target spreadsheet, then compare the worked result. This formula-availability check does not establish identical menus, keyboard shortcuts or workbook features, and it is not a product execution test. Keep this page bookmarked for the next time the same question comes up. Better still, repeat the steps once in your own workbook — doing it yourself is what turns a copied answer into something you remember. For “trim function in excel”, keep the input cells and the result visible while you check the formula in Excel. Follow the worked example and change one input at a time. The steps explain the workbook calculation; this page does not run a live calculator for that task.
Common mistakes
- Expecting
TRIMto remove non-breaking spaces (CHAR(160)) from web or PDF paste — it does not; useSUBSTITUTE(A2, CHAR(160), " ")beforeTRIM; CLEAN does not remove CHAR(160). - Assuming
TRIMstrips every internal space — it keeps single spaces between words and only collapses multiples, which is usually what you want. - Editing the original cell in place expecting it to change —
TRIMneeds a separate cell, then paste the result back as values.
Frequently asked questions
Why does TRIM not remove all the spaces?
TRIM only handles the regular space, CHAR(32). Spaces from web or PDF paste are often non-breaking spaces, CHAR(160), which TRIM ignores. Clean those with =TRIM(SUBSTITUTE(A2, CHAR(160), " ")). CLEAN removes control characters 0–31, not CHAR(160).
Does TRIM remove spaces between words?
Not the single spaces — it keeps one space between words and only collapses runs of two or more into one, along with removing leading and trailing spaces.
How do I trim spaces from a whole column?
Put =TRIM(A2) in a helper column, fill it down, then copy and Paste Special as Values back over the original column to replace the untrimmed text.
Other ways people ask this
This is also commonly searched as “function trim in excel”, “how to use trim function excel”, “how to use the trim function in excel” and “how do i use the trim function in excel”. They describe the identical operation, so you are in the right place no matter how you phrased it.
Why do people search for this in so many different ways?
Because the same task has many names. “function trim in excel”, “how to use trim function excel”, “how to use the trim function in excel” all point at the one operation explained on this page, which is why they all lead here.