In Excel: use =TRIM(text) — it removes leading and trailing spaces and collapses every run of internal spaces down to a single space.
Syntax
Arguments
| Argument | Description | |
|---|---|---|
text | required | The text or cell to clean of extra spaces. |
Related functions
14 characters removed · 25 characters
Non-breaking spaces from web copy-paste are normalised too — TRIM alone leaves those behind.
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 or CLEAN. 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. One habit worth forming early: name the cells that hold your inputs, so the formula reads in plain language instead of a string of cell addresses. A reviewer — or you in three months — can then follow the logic without decoding what B7 and D2 were supposed to mean, which is most of what makes a sheet maintainable.
In Google Sheets
Everything above works in Google Sheets too. Excel and Sheets share the formula syntax used here; only the surrounding menus are arranged differently. That portability is deliberate — learn it once and it follows you between the two tools and across Windows and Mac. Keep this page bookmarked for the next time the same question comes up. Better still, rebuild the example once in your own sheet — doing it yourself, with the tool above to check against, is what turns a copied formula into a technique you own. The short version of “trim function in excel”: the answer is at the top of this page, the tool proves it on your own numbers, and the sections above explain why it holds so the next variation does not stump you. Excel rewards people who reference cells instead of typing values and who keep inputs separate from formulas, because that is what makes a result you can audit months later. Build it once, deliberately, with the live tool as a check, and you convert a one-off lookup into a reusable skill — which is the whole point of learning the why and not just the what.
Common mistakes
- Expecting
TRIMto remove non-breaking spaces (CHAR(160)) from web or PDF paste — it does not; useSUBSTITUTE(A2, CHAR(160), " ")or CLEAN first. - 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), " ")) or with CLEAN.
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.
This guide also answers
- how to use trim formula in excel
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.