auto add page breaks

G

Guest

I import a report from Access into Excel that has grouped together East
Precinct, West Precinct, North Precinct and Central Precinct. Is there a way
I could have excel automatically insert a page break at the end of each
group? I want it all on the same spreadsheet, I just want East on page 1,
west on page 2 and so on. Can this be done?
 
G

Gord Dibben

If your data looks like this

east
east
east
west
west
west
etc
etc
etc

This macro will insert a pagebreak at each change of data column A

Sub InsertBreak_At_Change()
Dim i As Long
For i = Selection.Rows.Count To 1 Step -1
If Selection(i).Row = 1 Then Exit Sub
If Selection(i) <> Selection(i - 1) And Not IsEmpty _
(Selection(i - 1)) Then
With Selection(i)
.PageBreak = xlPageBreakManual
End With
End If
Next
End Sub


Gord Dibben MS Excel 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