Remove Spaces at the End of Text in Excel with TRIM

Formulas & functions · Updated November 18, 2026

To remove ordinary spaces at the end of text in Excel, put =TRIM(A2) in a helper column if the text is in A2, then fill the formula down. TRIM also removes leading spaces and reduces repeated spaces between words to one. If you need to preserve those other spaces, use the exact trailing-space formula below instead. Make a copy of the original column before replacing data.

What You’ll Need

  • An Excel workbook with the text values you want to clean.
  • A blank helper column beside the original data, so the cleaned results can be checked before replacing anything.
  • For the exact trailing-only method, Microsoft 365 or Excel 2021 or later, which includes XMATCH and SEQUENCE.

The instructions below are for Excel for Microsoft 365 on Windows. The formulas also work in current Excel for Mac; some ribbon labels or window layouts may look slightly different. Excel for the web supports TRIM and newer dynamic-array functions, but use the desktop app if you need to follow the ribbon steps exactly.

Step-by-Step

  1. Identify the source cells. Find the column containing the text and note its first data row. In the examples below, the first value is in A2 and the header, if present, is in A1. Check a few cells to confirm that unwanted spaces are at the right-hand end. A visible gap after a word may be a normal space, but imported data can also contain nonbreaking spaces or other invisible characters.
  2. Choose whether to clean all ordinary extra spaces or only the ending spaces. TRIM is the simplest choice for a typical list of names, labels, or descriptions: it removes leading spaces, removes spaces at the end, and converts runs of ordinary spaces between words to one space. Use the exact formula in step 3 if repeated spaces inside the text or spaces at the beginning are meaningful and must stay unchanged.
  3. Enter the appropriate formula in a blank helper column. With the original text in A2 and a sample value of Ada Lovelace , enter =TRIM(A2) in B2 to get Ada Lovelace. Notice that TRIM also removes the two leading spaces and reduces the double space between the names to one. If you want to remove only ending ordinary spaces, enter =IFERROR(LEFT(A2,XMATCH(TRUE,MID(A2,SEQUENCE(LEN(A2)),1)<>" ",0,-1)),"") in B2. With the same sample value, this returns Ada Lovelace: the ending spaces are gone, while the leading and internal spaces remain. The exact formula uses XMATCH and SEQUENCE, available in Microsoft 365 and Excel 2021 or later.
  4. Confirm that the result looks right. Click B2 and inspect the formula bar and the displayed result. If using TRIM, check that you are comfortable with the removal of leading spaces and the reduction of multiple internal spaces. If using the exact formula, compare the visible text carefully; the spaces retained at the start or between words can be difficult to see. You can temporarily widen the column or compare the value against the source.
  5. Fill the formula down the list. Select B2, point to the small square at the lower-right corner of its selection border, and double-click the fill handle to copy the formula down alongside adjacent data. Alternatively, select the formula cell and the destination range, then choose Home > Fill > Down. On Windows, Ctrl+D fills the selected range down; in Excel for Mac, Control+D is the corresponding fill-down shortcut. Check the final rows to make sure the formula reached every record.
  6. Review exceptional rows before replacing the source. Look for blank cells, formulas, unusual punctuation, and values that contain intentional repeated spaces. The exact formula returns a blank for a cell made entirely of ordinary spaces. TRIM returns a blank for ordinary spaces too. Keep the original column until you have checked representative results and any rows that matter especially, such as IDs or product codes.
  7. Replace the original values only if needed. If other formulas or systems need fixed text rather than formulas, select the cleaned results in column B and copy them. Select the original data cells in column A, then choose Home > Paste > Paste Values. This writes the cleaned text into the original cells instead of leaving formulas that depend on the helper column. Do not paste over a header unless you have included an appropriate header in your helper column.
  8. Save and verify the finished column. Save the workbook, then check several cells at the beginning, middle, and end of the data. If you pasted values, click a cleaned cell and confirm the formula bar shows text rather than a formula. Keep a separate copy of the original data if the exact spacing may be needed later.

Common Mistakes

Assuming TRIM changes only the end of a value. It does more: Excel’s TRIM removes ordinary leading and trailing spaces and changes each run of internal ordinary spaces to one. That is useful for inconsistent typing, but it can alter carefully formatted text. Use the XMATCH formula when you need to preserve all spaces except those at the end.

Expecting the formula to change the original cell automatically. A formula in B2 produces a cleaned result in B2; it does not edit A2. Keep a helper column while checking the output. To make the source column contain fixed cleaned text, copy the results and use Paste Values.

Typing over the source before checking the result. If a formula refers to A2 and you overwrite or delete A2 too soon, the result can change or disappear. Finish the review first, then copy and paste values. For important data, save a duplicate workbook or duplicate the sheet before making a bulk change.

Confusing spaces with other invisible characters. TRIM targets ordinary space characters (character 32). Web pages and exported files may contain a nonbreaking space (character 160), tabs, or line breaks. Those characters can look like spaces but are not all removed by TRIM. If the output is unchanged, investigate the character rather than repeatedly applying the same formula.

Forgetting to fill every row. A formula may be correct in B2 but absent from some lower rows. Double-clicking the fill handle usually follows adjacent data; if there are blank rows, it may stop early. Select the full destination range and use Home > Fill > Down, then inspect the bottom of the list.

Tips

Use a helper column even when the cleanup seems straightforward. It makes the before-and-after values easy to compare and gives you a simple way to undo the change: keep the source column and delete the helper column if the results are not suitable.

For repeated work, convert the data range to an Excel table with Insert > Table. A formula entered in a table column generally fills down through that column automatically and is applied to new rows. Check the table’s results when you add data, especially if new rows contain unusual spaces.

Do not judge a cell only by how it looks on the worksheet. A trailing space is often invisible, and column alignment can make it difficult to notice. A practical check is to compare the original and cleaned values, or use a formula that measures their lengths. With the source in A2 and its cleaned result in B2, =LEN(A2)-LEN(B2) returns the number of characters removed when the comparison is appropriate. For TRIM, that difference can also include leading or repeated internal spaces, not just trailing spaces.

When you are cleaning text that will be used for matching, sorting, or exporting, check a sample from each source system. Different systems may insert different whitespace characters. A cleanup formula that works for one file may not remove a nonbreaking space in another.

Troubleshooting

The spaces remain after using TRIM. The character may not be an ordinary space. One option is to replace nonbreaking spaces with ordinary spaces inside a cleanup formula, then apply TRIM. With the original text in A2, =TRIM(SUBSTITUTE(A2,CHAR(160)," ")) replaces nonbreaking spaces with ordinary spaces before trimming. This also applies TRIM’s normal behavior to the text: it removes leading and ending spaces and reduces repeated internal ordinary spaces to one. Check the result before using it across the full column.

The formula shows as text instead of calculating. Check that the cell is not formatted as Text. Select the formula cell, choose Home > Number Format > General, then press F2 and Enter to make Excel evaluate the existing entry. Also confirm that the formula begins with an equals sign and that Show Formulas is not turned on. On Windows, Ctrl+` toggles Show Formulas; on many Mac keyboards, the equivalent key combination uses Control+`.

Excel displays an error for the exact formula. Confirm that the Excel version supports XMATCH and SEQUENCE (Microsoft 365 or Excel 2021 or later), and that the formula has been entered with commas between arguments. Some regional settings use semicolons as formula separators; if Excel flags the commas, use the separator your installation expects. The formula is designed for ordinary spaces, not every possible whitespace character.

The exact formula returns blank unexpectedly. It returns an empty string when it cannot find a non-space character, including when the cell is empty or consists only of ordinary spaces. If a cell contains text but appears blank, check for nonbreaking spaces or other invisible characters. You may need to replace those characters separately before deciding how to trim the value.

The cleaned text looks different in the middle. That is expected if you chose TRIM and the original contained multiple adjacent ordinary spaces between words. Switch to the trailing-only formula if those internal spaces are important, then compare the outputs again. Also check that your formula points to the correct source cell; a reference to the wrong row can make a correct formula appear to produce an incorrect result.

Frequently Asked Questions

Does TRIM remove spaces only at the end?
No. Excel’s TRIM removes ordinary spaces at both ends and reduces repeated ordinary spaces inside the text to one. Use the exact trailing-only formula in this guide if you need to preserve leading and internal spacing.

Can I remove trailing spaces without a formula?
For a short list, you can edit cells manually, but it is easy to miss invisible spaces. A helper-column formula is more consistent for many rows. Copy the results and use Paste Values if you want to keep fixed text rather than formulas.

Will TRIM remove tabs or line breaks?
Not necessarily. TRIM is intended for ordinary spaces, not every whitespace or control character. Tabs, line breaks, and nonbreaking spaces may need to be replaced or cleaned separately, and you should verify that doing so does not remove meaningful content.

Will these formulas work in Excel for Mac?
TRIM works in current Excel for Mac. The exact formula requires XMATCH and SEQUENCE, so use Microsoft 365 or Excel 2021 or later. The formula logic is the same, though some ribbon locations and keyboard details can differ.

Can I use this on a whole column?
Yes. Enter the formula beside the first data row and fill it down only as far as the data extends. Avoid applying formulas to an entire worksheet column unless you have a specific reason; a bounded range or Excel table is easier to review and manage.

How do I know the spaces are actually gone?
Inspect the formula result and compare its character count with the source, keeping in mind that TRIM can remove or reduce spaces in several places. For exact trailing-only cleanup, compare the result with the original and check rows with known spacing issues before pasting values over the source.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.