Insert Page break in VBA - not working

dmcgimpsey

Active Member
Joined
Mar 30, 2004
Messages
268
Hi Folks:

I am trying to dynamically set up a report for the end user. What I wanted to do was to set up the output to print in landscape mode, and to put page breaks at specific row numbers.

My code is below - but it seems that it is not putting in the page breaks where I wanted them -

Also - I set up the report to force the page size to 1 wide by 55 long - to ensure that it does not span across the right side of the page

Code:

Sheets("METLIFE INC").Select


ActiveWindow.View = xlPageBreakPreview

ActiveSheet.HPageBreaks.Add Before:=Rows(72)
ActiveSheet.HPageBreaks.Add Before:=Rows(162)
ActiveSheet.HPageBreaks.Add Before:=Rows(233)



Ultimately, these lines will not be hardcoded as such -they will be set up logically but I have to at least get this to work first

Thanks in advance

Don
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try:

Code:
ActiveSheet.HPageBreaks.Add.Range("A72")
ActiveSheet.HPageBreaks.Add.Range("A162")
ActiveSheet.HPageBreaks.Add.Range("A233")
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,678
Members
452,937
Latest member
Bhg1984

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