Macro to add pagebreaks based on specific value found in column

slpsu98

New Member
Joined
Jun 4, 2021
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a report that does not have uniform columns or rows, but where the phrase TOTAL: appears, I have created a new column A w/ a certain value (the date) (using an If statement).
Where the date appears in column A I need to create a page break on the row BELOW the cell where the date in my new column A appears.
I have the following macro, which is sort of working, but it's creating a page break both ABOVE and BELOW the row so I need to eliminate the page break that is occurring in the row ABOVE the date.
Is this possible?

Here's the macro that I'm using:

Sub PageBreak()
'UpdatebyExtendOffice20181101
Dim xSRg As Range
Dim xRg As Range
On Error Resume Next
Set xSRg = Application.InputBox("Select key column:", "Kutools for Excel", xTxt, , , , , 8)
If xSRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
For Each xRg In xSRg
ActiveSheet.Rows(xRg.Row).PageBreak = xlPageBreakNone
If xRg.Value <> xRg.Offset(-1, 0).Value Then
ActiveSheet.Rows(xRg.Row).PageBreak = xlPageBreakManual
End If
Next xRg
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,215,830
Messages
6,127,134
Members
449,361
Latest member
VBquery757

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