Page Break on Pivot Table when printing - Is it possible to only page break at a blank row IF it goes over 1 page

Goodluckboss

New Member
Joined
May 25, 2014
Messages
25
Hey guys I have a pivot table that has groups of items. For example Group 052 has 3 items in it --> 1 blank row --> Group 053 has 5 items in it --> 1 blank row

If group 53 is cut off with a page break, is it possible to instead print up to group 0
2022-03-04_20-41-22.png
52 and continue Group 053 in a new page?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
The following code will loop through each horizontal pagebreak, starting at the top. For each pagebreak, if there's a value on both sides, it moves the pagebreak upward until it finds a blank row. Note that it assumes that the worksheet containing the data is the active worksheet.

VBA Code:
Option Explicit

Sub AdjustHorizontalPageBreaks()

    Dim originalView As XlWindowView
    Dim currentPageBreak As HPageBreak
    Dim currentLocation As Range
    Dim pageBreakCount As Long
 
    With ActiveWindow
        originalView = .View            'remember view for active window
        .View = xlPageBreakPreview      'change view to xlPageBreakPreview needed to adjust the pagebreaks
    End With
 
    pageBreakCount = 1
 
    On Error Resume Next
    Set currentPageBreak = ActiveSheet.HPageBreaks(pageBreakCount)
    If Not currentPageBreak Is Nothing Then
        Do
            Set currentLocation = currentPageBreak.Location
            If Len(currentLocation.Offset(-1, 0)) > 0 Then
                If Len(currentLocation) > 0 Then
                    Do
                        Set currentLocation = currentLocation.Offset(-1, 0)
                        If currentLocation.Row = 1 Or currentLocation.EntireRow.PageBreak <> xlPageBreakNone Then
                            Exit Do
                        End If
                    Loop Until Len(currentLocation) = 0
                    If currentLocation.Row > 1 Then
                        If currentLocation.EntireRow.PageBreak = xlPageBreakNone Then
                            Set currentPageBreak.Location = currentLocation
                        End If
                    End If
                End If
            End If
            Set currentPageBreak = Nothing
            pageBreakCount = pageBreakCount + 1
            Set currentPageBreak = ActiveSheet.HPageBreaks(pageBreakCount)
        Loop Until currentPageBreak Is Nothing
    End If
    On Error GoTo 0
 
    ActiveWindow.View = originalView    'change back to the original view
 
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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