Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Placing Text in Empty Table Cells.

Placing Text in Empty Table Cells

Written by Allen Wyatt (last updated March 11, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021


When Liliana has a table in a document, the company requirements state that each cell in the table must have something in it. This means that if a cell is otherwise empty, it must contain either a dash or the letters "N/A." Liliana wonders if there is a way that she can automatically place either a dash or "N/A" into the empty cells of a table.

The only way to do this is with a macro. You can create one that steps through each of the cells in a table and checks to see what it contains. If the cell is empty, then the text you desire is placed in the cell. Here is an example macro that works on all the tables in a document, checking each cell:

Sub ProcCells1()
    Dim tTable As Table
    Dim cCell As Cell
    Dim sTemp As String

    sTemp = "N/A"

    For Each tTable In ActiveDocument.Range.Tables
        For Each cCell In tTable.Range.Cells
            'An apparently empty cell contains an end of cell marker
            If Len(cCell.Range.Text) < 3 Then
                cCell.Range = sTemp
            End If
        Next
    Next
    Set oCell = Nothing
    Set tTable = Nothing
End Sub

If you decide that you want your empty cells to contain a dash instead of "N/A", all you need to do is change the text placed in the sTemp variable. If you prefer a macro that works with a single table instead of all the tables in a document, the following variation works great:

Sub ProcCells2()
    Dim tTable As Table
    Dim cCell As Cell
    Dim sTemp As String

    sTemp = "N/A"

    If Selection.Information(wdWithInTable) Then
        Set tTable = Selection.Tables(1)
        For Each cCell In tTable.Range.Cells
            'An apparently empty cell contains an end of cell marker
            If Len(cCell.Range.Text) < 3 Then
                cCell.Range = sTemp
            End If
        Next
    End If
    Set oCell = Nothing
    Set tTable = Nothing
End Sub

In order to use this variation, just make sure the insertion point is within the table you wan to process before you run the macro.

If you prefer to not use macros, then there is a different approach you could consider—simply make sure that your table contains the desired dashes or "N/A" text before you start putting information in it. You could create a table template that contains a dash or "N/A" in every cell, and then as you place other information in the cell you simply delete the default text. (The various ways you can set up table templates is covered in other issues of WordTips.)

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 (10773) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Word here: Placing Text in Empty Table Cells.

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

Inserting Dashes between Letters and Numbers

If you need to add dashes between letters and numbers in a string, the work can quickly get tedious. This tip examines ...

Discover More

Noting Inactivity within a Timeframe

There are many times when you are creating a worksheet that you need to analyze dates within that worksheet. Once such ...

Discover More

Showing a Dynamic Number Range in a Header

If you are creating a reference document of some type, you may want to include in the header of that document an ...

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 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Table Won't Flow to Second Page

Have you ever created a table that never seems to flow to a second page, even when it should? This could be caused by any ...

Discover More

Counting Values in Table Cells

In Excel it is easy to count how many times a certain character occurs in a column of cells. In Word, it is a bit ...

Discover More

Table Borders Won't Print

Print a table and you may be surprised if it has no borders. That could be because you actually have the borders turned ...

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 less than 9?

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.