Tables & Page Breaks

E

ed0211e

Hi! I'm new to VBA, so I don't think my problem is too difficult (but
I'm not really sure).

I have a table with 8 columns. Column 5 contains a year date (YYYY)
and is sorting in descending order. The years range from 2004-1986,
and there are a varying number of rows for each year (but all the rows
with the same year are together).

I'd like to create a macro that inserts a page break after each new
year.

If it helps, I could move the year column to the last position in the
table (so it would become the last column, column 8).

Thanks in advance for your help!
 
D

Doug Robbins - Word MVP

The following is a modification of a macro created to do something similar
and it assumes that there is no header row:

Dim scat As Range
Dim stab As Table
Dim i As Long
Set stab = ActiveDocument.Tables(1)
For i = 1 To stab.Rows.Count
Set scat = stab.Cell(i, 5).Range
scat.End = scat.End - 1
Set tcat = stab.Cell(i + 1, 5).Range
tcat.End = tcat.End - 1
If scat <> tcat Then
stab.Cell(i + 1, 1).Range.Paragraphs(1).PageBreakBefore = True
i = i + 1
End If
Next i


If there is a header row, change

For i = 1 to stab.Rows.Count

to

For i = 2 to stab.Rows.Count

--
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