auto add page breaks

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
Back
Top