Sub topic 4
Trim with a formula: the TRIM function
Assume you know how to select cells and ranges, enter formulas, and use the Google Sheets menu bar. This chapter focuses on cleaning spaces with a formula so the result remains repeatable when the source data changes.
What TRIM changes
TRIM is a Google Sheets function that removes unwanted spaces from text. It removes spaces at the beginning and end of a cell and reduces repeated spaces between words to one space.
For example, a cell containing North region becomes North region.
=TRIM(A2)This formula reads the text in A2 and returns a cleaned version. It does not change A2 itself. The formula result appears in the cell where you enter the formula.
A useful working model is:
Clean a column with TRIM
Suppose column A contains names with inconsistent spacing. Enter this formula in an empty helper column, such as B2:
=TRIM(A2)Then fill the formula down. Each row in column B shows the cleaned value from the matching row in column A.
| Original value in A | Formula in B | Result in B |
|---|---|---|
| ` Ana Ruiz ` | `=TRIM(A2)` | `Ana Ruiz` |
| `Marcus Lee` | `=TRIM(A3)` | `Marcus Lee` |
A helper column is a temporary or separate column used to calculate and review a transformed value. It lets you compare the original and cleaned data before replacing anything.
For a column that may grow over time, use ARRAYFORMULA. ARRAYFORMULA applies one formula to a range instead of requiring a separate formula in every row.
=ARRAYFORMULA(TRIM(A2:A))Place this formula in an empty column. It returns a cleaned result for each non-empty row in column A.
Common errors
Leaving the output range occupied
An array formula needs room to place its results. If cells below the formula already contain data, Google Sheets may show an error because the results cannot expand. Put the formula in an empty column or clear the intended output range first.
Overwriting the source too soon
TRIM returns a new value. It does not edit the source cell. Keep the original column until you have checked the results. If you later need cleaned text as fixed values, copy the formula results and use Edit > Paste special > Values only in a separate destination.
Expecting TRIM to remove every invisible character
TRIM handles ordinary spaces. Imported data can also contain non-breaking spaces or non-printing characters that look like spaces but are different characters. If a lookup still fails after trimming, inspect the data with additional cleanup functions such as CLEAN and SUBSTITUTE.
When to use a formula
Use TRIM when you want a cleanup step that can be repeated whenever the source data changes. Use the menu command Data cleanup > Trim whitespace when you want to clean selected cells directly and do not need to preserve a formula-based transformation.
A formula is safer during review because the original value remains visible beside the result.
Exercise
Cell A2 contains West Office . What formula returns West Office without changing A2?
Show answer
Enter =TRIM(A2) in another cell.