Set Page Break Cell Value Equals X with VBA

jwb1012

Board Regular
Joined
Oct 17, 2016
Messages
167
Hello everyone, I am attempting to use the code below to insert a page break above every row where column C = "BOE Summary",

But, the current code results in a Run Time Error 13: Type Mismatch. I would also like to set the print area from cell C2: "J" & End_Row (column J and the last row with data). And start the page break insertion beginning with the 2nd occurrence of "BOE Summary".

Any assistance would be much appreciated.


Code:
Sub PageBreaks()
Dim End_Row As Long, n As Long, Ins As Long
Dim Sh As Worksheet
    Application.ScreenUpdating = False
    
    End_Row = ActiveSheet.Range("L" & Rows.Count).End(xlUp).Row
        
        For n = End_Row To 3 Step -1
            Ins = ActiveSheet.Cells(n, "C").Value
            
            If Ins = "BOE Summary" Then
                Sh.Range(n).PageBreak = xlPageBreakManual
            
            End If
        Next n
            
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi jwb1012,

Does this do what you want...

Code:
Sub PageBreaks()


    Dim End_Row As Long, n As Long, Ins As String
    Dim Sh As Worksheet
    
    Application.ScreenUpdating = False
    End_Row = ActiveSheet.Range("L" & Rows.Count).End(xlUp).Row
        
    For n = End_Row To 3 Step -1
        Ins = ActiveSheet.Cells(n, "C").Value
            If Ins = "BOE Summary" Then
                ActiveSheet.HPageBreaks.Add Range("A" & n)
            End If
    Next n
            
    Application.ScreenUpdating = True
    
End Sub

HTH

igold
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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