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