The TRIM function in Google Sheets removes leading, trailing and repeated spaces from text, leaving a single space between words. Its job is to make messy data usable: text pasted from PDFs, emails, CRM exports or websites often carries extra spaces that break sorting, filtering, lookups and calculations, and TRIM cleans that text without you retyping it. The syntax is simple: =TRIM(text), where text is either a cell reference such as A2 or a value typed in quotes such as "  hello  ". You only need a Google account with Sheets access, a sheet open, and a few typed keys. It works the same in the browser, the iPhone app and the Android app, though formula editing on mobile is more fiddly, so the steps below assume the desktop browser version and note where mobile differs.

What You'll Need

  • A Google account with access to Google Sheets (free with any Google account).
  • A spreadsheet containing the text you want to clean, or a blank sheet if you want to practise first.
  • One empty column next to the text, because TRIM writes its result somewhere new, not in place.
  • Optionally, an example string to test with, such as Red Apple typed with deliberate extra spaces.

Step-by-Step

  1. Open your spreadsheet. Go to sheets.google.com or open the sheet from Google Drive. Click the tab for the sheet that holds the messy text.
  2. Pick a destination cell. Click an empty cell to the right of your data, for example B2 if your text sits in A2. Do not overwrite the original column yet, since you may want to compare the two.
  3. Type the formula. Enter =TRIM( and then either click the cell containing the text with your mouse, or type its reference, for example A2. Finish with a closing parenthesis so the formula reads =TRIM(A2), then press Enter.
  4. Check the result. The destination cell should now show the same words with no stray spaces at either end and only single spaces between words. A correctly trimmed version of Red Apple becomes Red Apple.
  5. Fill down the column. Click the destination cell once, then drag the small square handle in its bottom-right corner down to the last row of your data. Alternatively, hover over the cell, select the cell above's data range, or double-click the fill handle to auto-fill to the end of the adjacent data. Each row now gets its own trimmed copy.
  6. Convert formulas to plain text. Replacing the original column with formula results is risky because the formulas refer to that column. The safe method: select the whole TRIM column and press Ctrl+C (Cmd+C on Mac). Then right-click the first cell and choose Paste special, then Values only. The formulas become static text that you can copy over the original column.
  7. Replace the original data (optional). With the values-only copy selected, press Ctrl+C, select the top cell of the original column, right-click and choose Paste special, then Values only again. Delete the helper column when you are satisfied.
  8. Delete the temporary column safely. Before deleting anything, check that any formulas elsewhere that pointed at the helper column now point at the cleaned column. If you pasted values over the original data, formulas that referenced it keep working unchanged.
  9. Turn it into a repeatable cleanup. If you import data regularly, keep the TRIM formula in a permanent adjacent column, or wrap your lookup formulas in TRIM instead, for example =TRIM(VLOOKUP(D2, A:B, 2, FALSE)). That way mismatched spaces stop breaking matches.

Common Mistakes

  • Expecting TRIM to change the cell in place. It always returns a new value. You must overwrite or replace the original yourself, realistically via Paste special > Values only.
  • Leaving the formulas live and then deleting the source column. If TRIM points at column A and you delete column A, every result turns into an error. Convert to values first.
  • Forgetting parentheses. =TRIM A2 is not a valid formula in Sheets and will show an error; it must be =TRIM(A2).
  • Using TRIM to remove all spaces. It keeps single spaces between words on purpose. To strip every space, use SUBSTITUTE(A2," ","") instead.
  • Assuming TRIM removes non-breaking spaces. Classic non-breaking spaces, which are common in text copied from web pages, are not regular spaces and TRIM may leave them in place. A formula such as =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) handles them.
  • Typing extra spaces inside the formula. =TRIM( A2 ) generally still works, but spacing inside quoted text is exactly what gets trimmed, so be deliberate when typing sample values.
  • Applying TRIM to numbers or dates. It converts the input to text. If you trim a numeric column, sort and sum operations may behave unexpectedly; trim the text columns instead.

Tips

  • Use TRIM together with CLEAN when data comes from a PDF or a website: TRIM handles spaces while CLEAN removes non-printing control characters.
  • Wrap TRIM into the formula that consumes the data rather than cleaning the source column, for example inside VLOOKUP, MATCH, COUNTIF or IF. This avoids changing the raw data at all.
  • To spot problem cells quickly, create a helper column with =LEN(A2) before and after trimming; a difference confirms hidden spaces were present.
  • To trim text in place across a whole range without helper columns, select the range, open the Data menu and look for options to split or process text; more reliable is the formula approach, since the built-in text tools do not offer a direct in-place trim on every version.
  • ARRAYFORMULA can trim an entire column at once: =ARRAYFORMULA(TRIM(A2:A)) in a single cell fills the whole result range and automatically expands with new rows.

Troubleshooting

The result says #N/A or #REF!. The source cell has probably been deleted, or the formula no longer points at the right cell. Click the cell, check the formula bar and re-point it at the correct column.

Spaces still look like they are there. The character may be a non-breaking space or a non-printing character. Try the SUBSTITUTE/CHAR(160) combination above, or add CLEAN to the formula.

TRIM appears to do nothing. There may genuinely be no extra spaces, or the text is a number formatted to look spaced. Compare lengths with LEN to confirm.

The wrong cells got overwritten. Press Ctrl+Z (Cmd+Z on Mac) immediately to undo. If the undo window has passed, open File and then Version history to restore an earlier version; be aware this replaces your later edits unless you copy from the old version.

The formula works on one row but not below. The cell references were not filled correctly. Re-select the original cell and drag the fill handle instead of typing each formula manually.

Sorting still groups identical-looking words apart. TRIM removes spaces only. Check for inconsistent capitalisation, hidden characters in the middle of words, or different characters used where a space should be, then use SUBSTITUTE for those specific characters.

Frequently Asked Questions

Does TRIM remove all spaces?

No. It removes leading and trailing spaces and collapses runs of multiple spaces into a single space between words. To remove every space, use SUBSTITUTE.

What is the difference between TRIM and CLEAN?

TRIM handles spaces. CLEAN removes non-printing characters such as line breaks and control codes that often arrive with imported data. Use them together when text comes from outside Google Sheets.

Can I trim an entire column at once?

Yes, with ARRAYFORMULA. Enter =ARRAYFORMULA(TRIM(A2:A)) and the results spill down for every row that has data.

Does TRIM work in Excel and Google Sheets the same way?

The core behaviour is the same, but Excel's TRIM handles spaces slightly differently from Sheets in edge cases and Sheets may leave non-breaking spaces that Excel strips. If you move data between the two, test a sample first.

Why does TRIM turn my dates or numbers into text?

TRIM is a text function, so its output is text. If you need to keep numeric behaviour, clean the text in a helper column and use VALUE to convert it back to a number.

Can TRIM break my formulas?

Only if you overwrite the source column while formulas read from it, or delete a column that TRIM depends on. Convert TRIM results to values before restructuring your data.