detect empty table cells

T

TonyLogan

Is there any way I can replace all empty cells in a table with the text of my choosing (the letter X, for example)

Thanks.
 
D

Doug Robbins - Word MVP

Hi Tony,

Use a macro containing the following code:

Dim i As Integer, j As Integer
For i = 1 To ActiveDocument.Tables(1).Rows.Count
For j = 1 To ActiveDocument.Tables(1).Rows(i).Cells.Count
If Len(Trim(ActiveDocument.Tables(1).Cell(i, j).Range)) = 2 Then
ActiveDocument.Tables(1).Cell(i, j).Range = "X"
End If
Next j
Next i

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
TonyLogan said:
Is there any way I can replace all empty cells in a table with the text of
my choosing (the letter X, for example)?
 
T

Tony Logan

This works great. If, however, I don't know the number of tables in a document, is there a way to modify the coding so it runs on the active table (the table I have my cursor in), as opposed to a specific table as referenced by 'Tables(1)'

Thanks again

----- Doug Robbins - Word MVP wrote: ----

Hi Tony

Use a macro containing the following code

Dim i As Integer, j As Intege
For i = 1 To ActiveDocument.Tables(1).Rows.Coun
For j = 1 To ActiveDocument.Tables(1).Rows(i).Cells.Coun
If Len(Trim(ActiveDocument.Tables(1).Cell(i, j).Range)) = 2 The
ActiveDocument.Tables(1).Cell(i, j).Range = "X
End I
Next
Next

Please post any further questions or followup to the newsgroups for th
benefit of others who may be interested. Unsolicited questions forwarde
directly to me will only be answered on a paid consulting basis

Hope this help
Doug Robbins - Word MV
TonyLogan said:
Is there any way I can replace all empty cells in a table with the text o
my choosing (the letter X, for example)
 
D

Doug Robbins - Word MVP

Hi Tony,

Replace ActiveDocument with Selection

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Tony Logan said:
This works great. If, however, I don't know the number of tables in a
document, is there a way to modify the coding so it runs on the active table
(the table I have my cursor in), as opposed to a specific table as
referenced by 'Tables(1)'?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top