Using VBA to remove automatic page breaks

OldManDemosthenes

New Member
Joined
Apr 19, 2011
Messages
38
I know you can use the following code to setup page breaks:
Code:
Worksheets("Sheet1").Columns("M").PageBreak = xlPageBreakManual

What I am having trouble with is deleting automatic page breaks. My code orients the page with landscape. Right after this I need to delete all automatic page breaks then insert my own.

Thank you!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You can't delete an automatic page break; they will go away by themselves if your manual page breaks allow the row/columns between them to print on a single page.
 
Last edited:
Upvote 0
The page breaks are not going away. My code is just adding page breaks

Here's my code exactly. I only want page breaks at columns J, W, and AH and a freeze pane at B.

Code:
Sub PageSetup()
    
With Worksheets("Model")
[INDENT].PageSetup.Orientation = xlLandscape[/INDENT]
[INDENT].Columns("J").PageBreak = xlPageBreakManual[/INDENT]
[INDENT].Columns("W").PageBreak = xlPageBreakManual[/INDENT]
[INDENT].Columns("AH").PageBreak = xlPageBreakManual[/INDENT]
End With
    
Range("B:B").Select
[INDENT]ActiveWindow.FreezePanes = True[/INDENT]

End Sub
 
Upvote 0
Try this:
Code:
Sub PageSetup()
    With Worksheets("Model")
        .PageSetup.Orientation = xlLandscape
        .ResetAllPageBreaks
        .VPageBreaks.Add Before:=Columns("J")
        .VPageBreaks.Add Before:=Columns("W")
        .VPageBreaks.Add Before:=Columns("AH")
    End With
    Columns("B").Select
    ActiveWindow.FreezePanes = True
End Sub
 
Upvote 0
Then you need to reduce the margins and/or decrease the print scaling so that the data fits in the page width.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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