Insert page break "after" condition met?

lmmay

Board Regular
Joined
Jun 6, 2014
Messages
87
I am trying to use the following to print a multiple page worksheet.
Can not figure out what my error is.

VBA Code:
Sub Set_Print_Area()
'Unprotect Worksheet


ActiveSheet.Unprotect Password:="XXXXXXXe"


'Set Print and Review


    Dim c As Range
    Dim FirstAddress As String
   
    Set c = Columns("B").Find(What:="APPLICANT NAME:", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
    If Not c Is Nothing Then
        FirstAddress = c.Address
        Do
            ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=c.Offset(0)
            Set c = Columns("B").FindNext(c)
        Loop While Not c Is Nothing And c.Address <> FirstAddress
    End If
   
   
   x = ActiveSheet.UsedRange.Columns.Count
   Set lastCell = Cells.SpecialCells(xlCellTypeLastCell)
   ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), lastCell).Address
   ActiveSheet.Range("Q2655").End(xlUp).Select
   




ActiveSheet.PrintPreview
 
Last edited by a moderator:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Have you verified that the worksheet is unprotected?
 
Upvote 0
This is the macro I typically use for printing other forms. However, for this application, the form is 61 rows long and the columns are A -P. To print the scale is 45. The form has a Header and Footer
with the margins set at: Top=1.25; Bottom, Right and Left=0.5; Header & Footer=0.3

This macro allows the top rows to "bleed" into the bottom of Page 2, 3, etc and gets worse on each page. That is why I am trying to break the pages above each instance
of the row that has "Applicant" in the first row of the form.

Is there a better way to accomplish this?

Thanks

VBA Code:
Sub Set_Print_Area()
'Unprotect Worksheet

ActiveSheet.UnProtect Password:="reco6700"

'Set Print and Review

Dim x As Long, lastCell As Range
x = ActiveSheet.UsedRange.Columns.Count
Set lastCell = Cells.SpecialCells(xlCellTypeLastCell)
   ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), lastCell).Address
ActiveSheet.PrintPreview

'Protect Worksheet
      
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Password:="reco6700"
End Sub
 
Last edited by a moderator:
Upvote 0
Can you insert page breaks manually?
 
Upvote 0
Yes. However, most applicants using the form are not educated enough to insert manual page breaks.
 
Upvote 0
It works fine here. I don't have another suggestion unless you can put the workbook on box or dropbox and post a link.
 
Upvote 0
You can't set a page break on the first row.

Code:
If cell.Row > 1 Then .HPageBreaks.Add Before:=cell
 
Upvote 0
That adds another If statement. Where would this be placed? This replaces the page break statement after the "Do"?
 
Upvote 0
Replace

Code:
.HPageBreaks.Add Before:=cell

with

Code:
If cell.Row > 1 Then .HPageBreaks.Add Before:=cell
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

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