Inserting page breaks based on grouped value changes

Jammer

New Member
Joined
Sep 26, 2002
Messages
17
Hi.

I have a simple list that contains several columns. For example, Teacher, Period and Subject are possile column headers. Under each header are teachers listed by period and subject. Everytime the teacher and period (grouped) changes I would like to automatically insert a page break. For example, Teacher Smith period 2, Teacher Smith period 3, Teacher Jones period 2, Teacher Jones Period 5, Teacher Green Period 5, Teacher Green Period 5. Thus, it should not just change when it recognizes a new teacher but a new teacher-period group. How should this be accomplished? Any help would be appreciated. I can send a file if necessary.

o_O
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi Jammer:

Please look at the following simulation and clarify where do you intend to have the Page_Breaks inserted ...
y030524h1.xls
ABCD
1TeacherPeriodSubject
2Smith2
3Smith3
4Jones2
5Jones5
6Green5
7Green5
Sheet7
 
Upvote 0
Hi.

I need to have the page breaks inserted every time there is a change in both the TEACHER name AND the PERIOD, so that every page printed would contain a teacher's name and period.

Example:

Jones, Period 2 (on one page)
Jones, Period 3 (on one page)

Not Jones Period 2 and Jones Period 3 on the same page.
 
Upvote 0
Hi Jammer:

If I have understood you correctly, one of the ways to do what you want is by using the following code ...
Code:
Sub yInsertPageBreakAtPeriodInColumnB()
    For Each Cell In [A3:A7]
        If Left(Cell(1, 2), 6) = "Period" Then
            ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Cell
        End If
    Next Cell
End Sub

I have written the macro to be operated on the range A3:A7 as shown in the following simulation. Please adjust the range to suit your own specific requirement. In the simulation the red line shows the page-break inserted by the code:[RANGE=cls:xl2bb-100][XR][XH=cs:5]y030525h1.xls[/XH][/XR][XR][XH][/XH][XH]A[/XH][XH]B[/XH][XH]C[/XH][XH]D[/XH][/XR][XR][XH]1[/XH][XD=h:l]Teacher[/XD][XD=h:l]Period[/XD][XD=h:l]Subject[/XD][XD=h:r][/XD][/XR][XR][XH]2[/XH][XD=h:l]Jones[/XD][XD=h:l]Period2[/XD][XD=h:r][/XD][XD=h:r][/XD][/XR][XR][XH]3[/XH][XD=h:l]Jones[/XD][XD=h:l]Period3[/XD][XD=h:r][/XD][XD=h:r][/XD][/XR][XR][XH]4[/XH][XD=h:l]Jones[/XD][XD=h:r][/XD][XD=h:r][/XD][XD=h:r][/XD][/XR][XR][XH]5[/XH][XD=h:l]hockey[/XD][XD=h:r][/XD][XD=h:r][/XD][XD=h:r][/XD][/XR][XR][XH]6[/XH][XD=h:l]football[/XD][XD=h:r][/XD][XD=h:r][/XD][XD=h:r][/XD][/XR][XR][XH]7[/XH][XD=h:l]Smith[/XD][XD=h:l]Period5[/XD][XD=h:r][/XD][XD=h:r][/XD][/XR][XR][XH=cs:5][RANGE][XR][XD]Sheet13[/XD][XH][/XH][/XR][/RANGE][/XH][/XR][/RANGE]

Would this do?
 
Upvote 0
I'm sorry. This doesn't work and the diagram does not look correct. Each teacher and his corresponding period should be listed on its own page.

Jones, Period 2, and all its other fields should be totally separate from
Jones, Period 3
Smith, Period 1, Student Johnny & Smith, Period 1, Student Jane (same page)

Black, Period 2
Black, Period 3

Please also explain to me, how to basically say this in a macro. If the contents of A1 and A2 concatenated DO NOT equal the contents of the cells below them (B1 AND B2 concatenated) in a pre-sorted list, then put a page break, otherwise leave it alone.

Thanks.
 
Upvote 0
Book4
BCDE
3TeacherPeriodTeacher+PeriodSubject
4Smith2Smith2A
5Smith3Smith3B
6Jones2Jones2C
7Jones5Jones5D
8Green5Green5A
9Green5Green5B
Sheet1

CREATE a new Column as UNION OF TEACHER&PERIOD.
Now create a pivot with Teacher&pivot as the first col & then Period & then Teacehr or whichever u want. Check the layout of Ist column, & on Field Check the Box of Insert Page break after new item.
 
Upvote 0
Thank you. Your options have worked using a pivot table. I appreciate your help very much everyone.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,937
Latest member
BeerMan23

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