Auto Page Breaks

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a macro that saves to pdf and this works great, thanks to all your help

Is there a way to insert page breaks depending on data in column D

Column D has the headings for each selection of data beginning with "ZZ099...."

Hope this makes sense

Thanks
 

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.
Code:
Sub Add_Page_Breaks()
Dim c As Range
ActiveSheet.ResetAllPageBreaks
    For Each c In Range("D1:D" & Cells(Rows.Count, 4).End(xlUp).Row)
        If Left(c.Value, 5) = "ZZ099" Then ActiveSheet.HPageBreaks.Add Before:=c
    Next c
End Sub
 
Upvote 0
Hi jolivanes,

Many thanks for your help but this doesn't seem work

Each ZZ will have different numbers after it if that matters

Also I had set the scaling to 70% and the code resets this to 100%

Many thanks
 
Upvote 0
If you change
Code:
If Left(c.Value, 5) = "ZZ099"
to
Code:
If Left(c.Value, 2) = "ZZ"
Do you think that that might work?
If not, there are other ways.
As for the scaling, i am sure you can reset it in the code. Lets us know. (I assume you mean the Zoom level)
BTW, when I tried the code with the Zoom level set at 70, nothing changed in the Zoom level. Have you got something else in a macro that could trigger the change?
 
Last edited:
Upvote 0
Would this do it?
Code:
Sub Add_Page_Breaks()
Dim c As Range, zm As Long
zm = ActiveSheet.PageSetup.Zoom
ActiveSheet.ResetAllPageBreaks
    For Each c In Range("D1:D" & Cells(Rows.Count, 4).End(xlUp).Row)
        If Left(c.Value, 2) = "ZZ" Then ActiveSheet.HPageBreaks.Add Before:=c
    Next c
ActiveSheet.PageSetup.Zoom = zm
End Sub
 
Upvote 0
Hi jolivanes,

Many thanks for the code, it almost works how I need it to

It does put every "ZZ" on a different page instead of as many "complete" ZZ's it can

Thanks
 
Upvote 0
If you put page breaks at intervals, it's meant to do that. That is what you asked for.
 
Upvote 0
Hi jolivanes,

my apologies, is there a way to allow as many "complete" ZZ's on one sheet, then pagebreak and again on the second etc etc

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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