Solved

Macro to format table cells

Posted on 2006-11-14
2
371 Views
Last Modified: 2008-02-01
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
Comment
Question by:daleoran
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 125 total points
ID: 17937515
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
 
LVL 10

Author Comment

by:daleoran
ID: 17937704
Brilliant - Many thanks :)

Michael
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now