K
KC Rippstein
I have a sheet set up with a pivot table that is ready to print, except the
auto-positioning of page breaks sometimes breaks up related items. Main row
fields are in column A, and sub-related items are directly underneath that
and indented in column B (like an outline view). I'd like to see if the
page break is happening in the middle of the sub-items (so B has a value)
and just move the break up above the main row item (where B is empty).
Here is my humble attempt so far, which does the job correctly once but then
does not advance down the worksheet. I think once I set a manual page
break,
it messes up my For...Next loop because all the other auto-page breaks
following are reassigned??
'==================
Sub FormatPageBreaks()
Dim oHPgbr As HPageBreak
Dim iRow As Long
ActiveSheet.ResetAllPageBreaks
On Error Resume Next
For Each oHPgbr In ActiveSheet.HPageBreaks
iRow = oHPgbr.Location.Row
If Cells(iRow, "B").Value = "" Then
Else
Do Until Cells(iRow, "B").Value = ""
iRow = iRow - 1
Loop
Rows(iRow).Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If
Next
End Sub
auto-positioning of page breaks sometimes breaks up related items. Main row
fields are in column A, and sub-related items are directly underneath that
and indented in column B (like an outline view). I'd like to see if the
page break is happening in the middle of the sub-items (so B has a value)
and just move the break up above the main row item (where B is empty).
Here is my humble attempt so far, which does the job correctly once but then
does not advance down the worksheet. I think once I set a manual page
break,
it messes up my For...Next loop because all the other auto-page breaks
following are reassigned??
'==================
Sub FormatPageBreaks()
Dim oHPgbr As HPageBreak
Dim iRow As Long
ActiveSheet.ResetAllPageBreaks
On Error Resume Next
For Each oHPgbr In ActiveSheet.HPageBreaks
iRow = oHPgbr.Location.Row
If Cells(iRow, "B").Value = "" Then
Else
Do Until Cells(iRow, "B").Value = ""
iRow = iRow - 1
Loop
Rows(iRow).Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If
Next
End Sub