VBA Print Page Breaks

alfordtp

Board Regular
Joined
Oct 3, 2008
Messages
62
I have a sheet that shows account summaries for clients that are 5-10 rows long. When I print out the summary, I cannot use the "fit to x pages tall" method because I cant guarantee that it will not split in the middle of an account summary. I want to find the last full account summary that fits on the page, then create a page break right after that, then continue to do that for all pages.

The header cell for each account summary starts with the word "account" in it. I can filter/find those cell row numbers. I'm not sure how to set the page break, then check again, then set the second page break, then check again...

Any help is appreciated!!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try this

VBA Code:
Sub set_print_page_breaks()
  Dim f As Range, r As Range, cell As String
  Set r = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
  Set f = r.Find("account", , xlValues, xlWhole)
  ActiveSheet.ResetAllPageBreaks
  ActiveSheet.DisplayPageBreaks = False
  If Not f Is Nothing Then
    cell = f.Address
    Do
      ActiveSheet.HPageBreaks.Add Before:=f
      Set f = r.FindNext(f)
    Loop While Not f Is Nothing And f.Address <> cell
  End If
End Sub
 
Upvote 0
not sure what the "Find" function is supposed to do in this situation. there will be 10+ accounts on this summary worksheet. I dont want each account to have their own page. I only want to prevent the page break from split an account block into two pages.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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