Written by Allen Wyatt (last updated March 11, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365
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:
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, 2021, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Placing Text in Empty Table Cells.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Word allows you to format your text using different languages. If you are working with a right-to-left language, you may ...
Discover MorePress the Tab key in a table, and Word dutifully moves to the next cell in that table. Press it in the last cell of a ...
Discover MoreTables are a great way to organize the information in a document. If your table gets quite long, you may not want to ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-08-19 00:44:35
Ricardo
Thanks a lot! Really helpful!!
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments