Adding Page Breaks Before Recurring Data in Column "A"

fallinup00

New Member
Joined
Jan 16, 2013
Messages
8
Hi,

I am trying to modify the code below to add horiz. page breaks before each instance of the word "Employer" in column A. The code, as it is below, works perfectly, but it places the page break after the row rather than before it.

If I change the line from:
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(1) 'adds break after
to:
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(0)
or
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c

I receive errors when running the marco.

Any ideas?

Cheers,
-A

Original Code:

Dim c As Range
Dim FirstAddress As String

Set c = Columns("A").Find(What:="Employer", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(1)
Set c = Columns("A").FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Did you try:
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(-1)

Positive 1 moves to the next, -1 should move above

Just a thought.
 
Upvote 0
Just a guess; try changing:
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(1)
to:
If c.Row <> 1 Then ActiveSheet.HPageBreaks.Add Before:=c
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top