Removing Whitespace from Table Cells

Written by Allen Wyatt (last updated August 16, 2025)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365


When Gina is editing documents created by others, she often needs to remove whitespace (spaces, tabs, hard and soft returns) from the end of cells in a table. She wonders if there is a way to do this with Find and Replace, or if she needs to use a macro to do it.

The answer depends on the information in your tables. If the only whitespace is actual spaces, then you can get rid of them by adjusting the alignment in your table cells. That approach is detailed fully in this WordTip:

https://tips.net/T9994

If you have other whitespace characters besides spaces, then you can try a Find and Replace approach by following these steps:

  1. Press Ctrl+H. Word displays the Replace tab of the Find and Replace dialog box.
  2. Click the More button, if it is available. (See Figure 1.)
  3. Figure 1. The Replace tab of the Find and Replace dialog box.

  4. Make sure the Use Wildcards check box is selected.
  5. Enter the following in the Find What box: ([!^13^l^t]@)[ ^t^13^l]{1,}
  6. Enter the following in the Replace With box: \1
  7. Click Find Next to step through each occurrence and make replacements, as appropriate.

There is one major drawback to using this approach: You need to make sure you don't click Replace All in step 6. If you do, then any trailing whitespace in your entire document is replaced. This may sound like a good thing, but it isn't because hard returns and soft returns are removed, which can end up messing up your formatting. Stepping through one change at a time, however, may give you the results you want.

If you need to strip trailing whitespace quite a bit, you'll get the most satisfactory results by using a macro. Here's an example of one that will do the job:

Sub TrimTableCells()
    Dim tbl As Table
    Dim cel As Cell
    Dim rng As Range
    Dim txt As String
    Dim sRtxt As String
    Dim sMsg As String

    If Selection.Information(wdWithInTable) Then
        Set tbl = Selection.Tables(1)   ' current table

        ' Loop through each cell in the table
        For Each cel In tbl.Range.Cells
            Set rng = cel.Range

            ' Exclude the end-of-cell marker
            rng.End = rng.End - 1

            ' Remove trailing whitespace
            txt = RTrim(rng.Text)
            sRtxt = Right(txt, 1)
            Do While sRtxt = " " Or sRtxt = Chr(9) Or sRtxt = Chr(11) Or sRtxt = Chr(13)
                txt = Left(txt, Len(txt) - 1)
                sRtxt = Right(txt, 1)
            Loop
            rng.Text = txt
        Next cel
        sMsg = "Trailing whitespace and returns removed from all cells."
    Else
        sMsg = "The insertion point is not inside a table."
    End If
    MsgBox sMsg, vbInformation
End Sub

Just place the insertion point with a table and then run the macro. It looks for any whitespace characters—spaces, tabs, soft returns, and hard returns—at the end of each table cell and, if it finds one, it deletes the character.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (6200) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Creating New Windows

If you need to look at different parts of the same worksheet at the same time, the answer is to create windows for your ...

Discover More

Locked File Puzzle

What would you do if every time you opened a workbook Excel told you it was locked? Here's how you can try to recover ...

Discover More

Turning Off the Clipboard Icon

When you paste information into a document, Word normally displays a small icon to the right of what you pasted. Some ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2019. Spend more time working and less time trying to figure it all out! Check out Word 2019 For Dummies today!

More WordTips (ribbon)

Clearing the Contents of a Table

Want to get rid of information within a table, but not the table itself? Here's a guide to understanding the effects that ...

Discover More

Unwanted Vertical Lines in a Table

When you print a table that includes borders, those borders should be crisp and clear on the printout. If you get some ...

Discover More

Placing Text in Empty Table Cells

Tables are often used to organize information into an understandable format. If your company requires that tables in ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one more than 8?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.