Macro to Remove Page Breaks

vmottert

Board Regular
Joined
Aug 30, 2003
Messages
215
I am working on a simple macro to let users remove unwanted page breaks with a keyboard shortcut. Here is what I have.

Sub RemovePageBreaks()
ActiveWindow.SelectedSheets.HPageBreaks.Delete Before:=ActiveCell
End Sub

Seems like it should work but I get the error message: "Object doesn't support this property or method."

Any help appreciated.

Vernon
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Bit of a botch - doesn't use VBA

Right click the tool bar (any)

Click Customize..

Under the command tabs - click insert - then drag PAGE BREAK onto a task bar.


Now ALT+B will remove the above page break. or add a new one
 
Last edited:
Upvote 0
To delete all on the activesheet:
Code:
Sub RemovePageBreaks()
  Dim pb As HPageBreaks
  For Each pb In ActiveSheet.HPageBreaks
    pb.Delete
  Next pb
End Sub
 
Upvote 0
kgkev,
Yep, that works. Little work to do and undo as needed, though. And harder to communicate to users than "Press Ctrl + Shift + R". Might have to do though.
Thanks,
Vernon
 
Upvote 0
Kenneth,
Thanks. But this is for use on a report that the user may want an easy way to delete only selected page breaks to control the number of pages in the print job. My idea was for the user to place the cursor under a page break and press [ Ctrl + Shift + R ] to remove a page break. It would be quicker to do this from the keyboard for a lot of them than with the mouse.
Vernon
 
Upvote 0
Alternatively to make my method easier you could use

alt+IB

ie hold ALT then type I B
 
Upvote 0
kgkev,
You're right about the Alt+IB. It is about as easy as [ Ctrl + Shift + R ] and doesn't require a macro. Sometimes I think too much :)
Thanks twice,
Vernon
 
Upvote 0

Forum statistics

Threads
1,223,966
Messages
6,175,662
Members
452,666
Latest member
AllexDee

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