Contact

TRIM Function in Microsoft Excel: Formula, Examples & Troubleshooting

Text Beginner Microsoft Excel

Learn the TRIM formula in Microsoft Excel: remove unwanted ordinary spaces from a text string, with reproducible examples, expected answers and compatibility cautions.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: Use TRIM to remove unwanted ordinary spaces from a text string. The example below supplies exact inputs and independently calculated expected results, so you can check your formula before replacing the demonstration values with real workbook data.

Verification: The function is covered by a vendor reference or its published formula catalogue. The worked outputs here are independently reasoned, not screenshots or native test results from Microsoft Excel. Check release-specific support and argument details in the referenced vendor help.

Availability and version history

  • Introduced: Introduction version not established by the official history reviewed.
  • Availability: Official help lists Excel for Microsoft 365, Excel for Microsoft 365 for Mac, Excel 2024, Excel 2024 for Mac, Excel 2021, Excel 2021 for Mac, Excel 2019, Excel 2016.
  • Checked: October 14, 2026; official TRIM reference. Documentation check, not a new native test; existing example-verification notes retain their scope.

Syntax and arguments

=TRIM(text)

Text or cell containing extra ASCII-style spaces. In formula syntax, square brackets mark optional arguments; do not type square brackets into an ordinary formula unless the particular function requires array notation. The separator shown is for the example locale and might change with spreadsheet settings.

When to use it: Apply TRIM to imported labels before COUNTIF or VLOOKUP when exact matching unexpectedly fails.

Prepare the example inputs

The original two examples are self-contained text formulas. Enter each in a blank cell, keeping quoted text and spaces exactly as shown. Additional examples below specify any required input cells; place their formulas outside those sources.

Worked example: exact formula and expected output

=TRIM("  East  team  ")

Expected result: East team. Leading/trailing spaces are removed and the double interior space becomes one.

  1. Select an unused output cell (for example H2 if the practice table occupies A1:F9).
  2. Enter the formula exactly as shown, including the opening equals sign and quoted text.
  3. Compare the displayed answer to the expected result, then inspect the source cells if it differs.

For a range formula, the row numbers include data rows only unless the example explicitly refers to headers. A result that looks plausible may still be wrong if it references the wrong column.

Second example: a different input

=TRIM("  Pad   East ")

Expected result: Pad East. The cleaned text has one separator space between words.

This second check uses the same function with a different input, helping you identify whether the first result was coincidental or caused by a shifted reference.

Correct a known nonbreaking space before trimming

Microsoft states that TRIM targets ordinary ASCII space 32 and does not remove Unicode nonbreaking space 160 by itself. A complete replacement formula needs the source text as well as the old and new characters.

Construct a reproducible source in A2:

=UNICHAR(160)&"North"&UNICHAR(160)&UNICHAR(160)&"Depot"&UNICHAR(160)

UNICHAR supplies the specified Unicode character without assuming a platform-specific extended CHAR code page. The source has 14 characters: ten letters and four nonbreaking spaces.

Then enter:

=TRIM(SUBSTITUTE(A2,UNICHAR(160)," "))

The expected result is North Depot, length 11. SUBSTITUTE first changes the four known nonbreaking spaces to ordinary spaces; TRIM removes the two end spaces and reduces the two internal spaces to one.

This is an explicit rule for a known character, not a universal invisible-character cleaner. Replacing or removing spaces can alter identifiers and fixed-width fields. Retain the original and verify that this normalization is allowed before using the cleaned text as a key.

Important edge cases and a common mistake

Watch out: TRIM does not remove Unicode nonbreaking space 160 by itself. Use the complete source/old/new replacement formula demonstrated above when that character is known and replacement is appropriate.

For older workbooks, verify the specific release and locale; the availability section records the current documentation scope without inferring an undocumented introduction date.

Troubleshooting in Microsoft Excel

Break a complex expression into helper cells and inspect the stored input types. A number-stored-as-text warning may be relevant for quantities but expected for text identifiers. #NAME? suggests a misspelling or an unavailable new function. #VALUE! often indicates a wrong argument type; #SPILL! on array functions often means output cells are occupied.

If you get the wrong answer but no error, try these checks in order: (1) evaluate the simplified first example; (2) confirm the cell values and data types; (3) check the exact row and column boundaries; (4) verify quoted text, comparison operators and separators; (5) only then add more criteria or nested functions.

For a reproducible comparison with another spreadsheet product, use the same input values in both applications and record the installed version and locale. Different default matching behavior or handling of empty values can be a migration issue rather than a mathematical disagreement.

Moving this formula between spreadsheet programs

Excel generally uses commas in English-language help formulas; LibreOffice and Collabora Calc commonly use semicolons. An identically named function may still have different matching defaults, dynamic-array behavior or version support.

Related guides already published for this function: LibreOffice Calc | Apache OpenOffice Calc | Gnumeric | Calligra Sheets | PlanMaker 2026

If a comparison tool says Not researched here, that means we do not yet have a checked guide for that software. It does not mean the software lacks this function. See the 12-program comparison tool for a guide-coverage matrix.

Official reference and editorial verification

Evidence level: Direct function documentation reviewed October 14, 2026; example outputs verified by direct reasoning/arithmetic where applicable. No execution in Microsoft Excel was performed. Some platform-, language- and release-specific edge cases remain for native testing.