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:
HPageBreaks still not breaking on the "Applicant Name:" row.
I give up!
Will have to teach my Applicants how to manually set the page breaks.

Thanks for trying to help my feeble attempt.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
The code ran fine for me on your workbook.
 
Upvote 0
The pages broke correctly on page 4, 5, & 6, which should be the max anyone will need?
 
Upvote 0

Forum statistics

Threads
1,215,221
Messages
6,123,699
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