← All how-to recipes

How to remove extra spaces from text

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

Strip leading, trailing, and repeated internal spaces so text is clean and comparable.

The formula

AppFormulaNotes
Excel=TRIM(A2)Removes leading/trailing spaces and collapses internal runs to one.
Google Sheets=TRIM(A2)Identical.
LibreOffice Calc=TRIM(A2)Identical.

How it works

TRIM removes every space from the start and end, and reduces any run of spaces between words to a single space. ' hello world ' becomes 'hello world'. Combine with CLEAN() to also strip non-printing characters.

Verified, not just documented

We ran =TRIM(A2) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned hello world — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned hello world for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run Excel.

Functions used

TRIM — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons