Deleting blank rows at the end of a table

J

Jean Pereira

Using Word XP 2003

My Word doc contains a table with 10 rows with a macro inserting info in
rows 8-10 after it has done steps below.

My macro also inserts 3 rows below row 5 based on whether To: or CC: boxes
in a form contain text. If this is the case, I end up with multiples of 3
additional empty rows at the bottom of the table. If there are no rows
inserted, everything is okay and there are no extra blank rows.

How can I either delete any blank rows of which there could be any multiple
of 3 or would it be better only to have 7 rows in my table and if there are
no additional rows inserted, get the macro to insert 3 rows at the end and
put the info in them?


Thanks in advance.
 
D

Doug Robbins - Word MVP

The following code will delete blank rows:

Dim flag As Boolean, i As Long, j As Long, atable As Table
Set atable = Selection.Tables(1)
With atable
For i = .Rows.Count To 1 Step -1
flag = False
For j = 1 To .Columns.Count
If Len(.Cell(i, j).Range) > 2 Then
flag = True
Exit For
End If
Next j
If flag = False Then
.Rows(i).Delete
End If
Next i
End With

Probably better however to only add rows if you need them.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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