Page Breaks Macro

B

Brian Matlack

Hi!
I would like to clear all page breaks and set a page break between each
change in rows in column A example, I want a page break between row 2
and 3. I'll set row 1 to repeat at the top of the printed page.
A B
1 Dept. Name
2 02 Jack
3 02 Bill
4 03 Bob

How would the code look for a task like this?

As always, any help or direction is greatly appreciated!
And thanks for your time!!
 
G

Guest

Dim dblRow As Double

ActiveSheet.ResetAllPageBreaks

ActiveSheet.PageSetup.PrintTitleRows = "$1:$1"

Range("B2").Select

Do
dblRow = dblRow + 1
If Len(ActiveCell.Offset(dblRow, 0).Value) <> 0 Then
If ActiveCell.Offset(dblRow, 0).Value <> _
ActiveCell.Offset(dblRow - 1, 0).Value Then
ActiveWindow.SelectedSheets.HPageBreaks.Add _
Before:=ActiveCell.Offset(dblRow, 0)
End If
Else
Exit Sub
End If
Loop


HTH,
 

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