Dynamic Page breaks - VBA

eoinymc

Board Regular
Joined
Jan 29, 2009
Messages
203
Hi,

I have a sheet that I want to dynamically set the page break within a dynamically defined print area.

Here is the code I have:

Code:
Table1.PageSetup.PrintArea = "$A$1:$R$" & FRBottom + 3    With Table1.PageSetup
        .PrintTitleRows = "$1:$7"
        .LeftMargin = Application.InchesToPoints(0.15748031496063)
        .RightMargin = Application.InchesToPoints(0.15748031496063)
        .TopMargin = Application.InchesToPoints(0.47244094488189)
        .BottomMargin = Application.InchesToPoints(0.393700787401575)
        .HeaderMargin = Application.InchesToPoints(0.511811023622047)
        .FooterMargin = Application.InchesToPoints(0.511811023622047)
        .Orientation = xlPortrait
        .CenterHorizontally = True
    End With
    
    Set Table1.VPageBreaks(1).Location = Table1.Range("R1")
    Set Table1.HPageBreaks(1).Location = Table1.Cells(FRBreak + 1, 1)

Where FRBottom is a variable which is the bottom row of the print area and FRBreak is the variable where I want to set the page break.

Do I need the VPageBreaks line of code?

What I'm looking for is the first page to be A1:R-FRBreak and the second page to be A-FRBreak+1:R-FRBottom

Anyone able to help me?

Thanks,

Eoin
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I'm assuming that in some instances the print area may not contain a horizontal page break. Therefore, you'll need to add one at the desired location, instead of moving the first horizontal page break to the desired location. Try replacing...

Code:
Set Table1.HPageBreaks(1).Location = Table1.Cells(FRBreak + 1, 1)

with

Code:
Table1.HPageBreaks.Add Table1.Cells(FRBreak + 1, 1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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