Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

Macro to format table cells

Hi there,
I need a macro that will scan down through a document, looking for any tables in it. When it finds a table it will scan the cells and if it finds any blank ones it will insert the text "N/A" (without the quotes). It then moves onto the next table (if there is one) does the same and continues on until it reaches the end of the document.

Many thanks in advance

Michael
0
daleoran
Asked:
daleoran
1 Solution
 
GrahamSkanCommented:
Hi Mike.

Try this one:

Sub DefaultCellData()
    Dim tbl As Table
    Dim cl As Cell
   
    For Each tbl In ActiveDocument.Tables
        For Each cl In tbl.Range.Cells
            If Len(cl.Range.Text) < 3 Then 'cell range returns visible text + 2 format characters
                cl.Range.Text = "N/A"
            End If
        Next cl
    Next tbl
End Sub
0
 
daleoranAuthor Commented:
Brilliant - Many thanks :)

Michael
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now