Set page break with VBA?

Russk68

Well-known Member
Joined
May 1, 2006
Messages
589
Office Version
  1. 365
Platform
  1. MacOS
Hi All!
Is it possible to set page breaks by the value of a cell?
Example:
Cell A50="Page Break". Page break is the inserted in row 50.

Thank you!

Russ
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Adds a Page Break above the "Page Break" Row.
Code:
Sub Maybe()
With ActiveSheet
    .ResetAllPageBreaks
    .HPageBreaks.Add (.Cells(.Columns(1).Find("Page Break", , , 1).Row, 1))
End With
End Sub
 
Upvote 0
Hi Jolivanes
This worked when I first tried it but then it stopped. I pasted your code in the sheet again and I still can't get it to work.
I'll try agin in a different workbook.
Thank you!
 
Upvote 0
If it worked initially, something changed to make it not work.
The spelling of "Page Break"? Capitalization? Leading or trailing spaces?
It needs to be exact as in the code.
 
Upvote 0
I understand.
Does changing sheets trigger the macro?
 
Upvote 0
No, it does not.
You have to invoke it.
The code should be in a regular module, not a Sheet module.
If you want the code triggered when changing sheets, you have to let us know.
In Post #3 you said that it worked when first tried. How did you make it work?
 
Upvote 0
I did paste the code in the sheet.
I believe it would work when I clicked on the Page Break Preview.
I will try in a regular module.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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