Insert Page Break every 35 rows; unless there is a number in C cell, the PB in row above.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
758
Hi! Thank you for your kind time.

Can you please help with a VBA code that page breaks the rows of sheet "Report".

A. PB Every 35 rows. The rows range is Row 1:600.

B. If the row that will have a Page Break has data in the C column (current row).

The page break will take place in the upper row (offset); instead of the current row.

Guys you rock! Thank you very much
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Does this get you close to what you want...

Code:
Sub PageBrk()
    
    Dim wsR As Worksheet: Set wsR = Worksheets("Report")
    Dim i As Long
    Dim rngC As Range
    
    wsR.ResetAllPageBreaks
    Set rngC = wsR.Range("C1:C600")
        For i = 35 To 600 Step 35
            If rngC.Cells(i) = "" Then
                wsR.HPageBreaks.Add before:=rngC.rows(i + 1)
            Else
               wsR.HPageBreaks.Add before:=rngC.rows(i)
            End If
        Next
    
End Sub
 
Upvote 0
You're very very welcome. I was happy to help. Thanks for the feedback!
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,195
Members
449,072
Latest member
DW Draft

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