Macro to Insert Page Breaks on Pivot Table (Excel 2003)

rickincanada

Board Regular
Joined
Aug 31, 2010
Messages
61
I currently have a a pivot table which groups by Period (column a) and then by Employee (column b). What I need to do is have a macro go through and insert a page break at the end of each employee.

My thinking is that I could look for each cell in column B that contains the word "Total" and then insert a page break 1 row below each of those. This sounds good in theory except I have no idea how to do this...if it is even possible.

Any assistance you can provide would be greatly appreciated. Thanks in advance - Rick.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Use this code in a macro or a function block or a button code block
Code:
    oldrow = 0
    currow = 1
    Columns("B:B").Select
    searchstring = "Total"
    
    While oldrow < currow
        oldrow = currow
        On Error GoTo finish
        Selection.Find(What:=searchstring, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        currow = ActiveCell.Row + 1
        ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Rows(currow)
    Wend
    
    MsgBox ("It's Done Dude!")
    Exit Sub
    
finish:
        Err.Clear
        MsgBox ("Dude! search string not found :(")
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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