Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forced page breaks

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
Is it possible to 'force' a page break in Excel dependant on the value in a cell? for example if you had a list of data for printing where one of the columns was a date field how could you force excel to start a new page at each change in date?

Craig
 
Hi,

One simple way is to use the Subtotal Wizard and select Page Break between groups.

Or you could write a routine. Macro record inserting a page break as a model for that code (I do this ALL THE TIME!)

Loop thru your list and at the appropriate row, add the HPageBreaks.

Skip,
Skip@TheOfficeExperts.com
 
Hi Skip
Like the sound of the second option, but not sure how to do the loop, can you advise?

Craig
 
Code:
sPrev = ""
With ActiveSheet.UsedRange
  For r = .Row to .Row + .Rows.Count - 1
    sThis = Cells(r, DateColumn).Value
    If sThis <> sPrev AND sPrev <> &quot;&quot; Then _
           Activesheet.HPageBreaks.Add Before:=Cells(r, DateColumn)
    sPrev = sThis
  Next
End With
Note: DateColumn is the column number containg Date

Skip,
Skip@TheOfficeExperts.com
 
Thanks Skip
That did the trick

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top