#1   Report Post  
Rob
 
Posts: n/a
Default Page breaks

I have a spreadsheet that has client numbers in the first column. I'd like to
be able to automatically put in page breaks for each client number. For
example, say rows 1 through 5 are client number 1, rows 6 & 7 are client
number 2, 8 through 15 are client 3 and so on. I'd like to have auto page
breaks at row 6, 8, 16, etc. Any ideas?
  #2   Report Post  
Paul B
 
Posts: n/a
Default

Rob, try this

Sub InsertBreaks()
Set rng = Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp))
For Each cell In rng
If Trim(cell.Value) < _
Trim(cell.Offset(-1, 0).Value) Then
ActiveSheet.HPageBreaks.Add cell
End If
Next
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003


"Rob" wrote in message
...
I have a spreadsheet that has client numbers in the first column. I'd like
to
be able to automatically put in page breaks for each client number. For
example, say rows 1 through 5 are client number 1, rows 6 & 7 are client
number 2, 8 through 15 are client 3 and so on. I'd like to have auto page
breaks at row 6, 8, 16, etc. Any ideas?



  #3   Report Post  
Gord Dibben
 
Posts: n/a
Default

Rob

Sub Insert_Pbreak()
Dim OldVal As String
Dim Rng As Range
With Application
.Calculation = xlManual
.ScreenUpdating = False
End With
OldVal = Range("A1")
StartTime = Timer
For Each Rng In Range("A1:A300") '<< change range

If Rng.text < OldVal Then
Rng.PageBreak = xlPageBreakManual
OldVal = Rng.text
End If
Next Rng
MsgBox Timer - StartTime
With Application
.Calculation = xlAutomatic
.ScreenUpdating = True
End With



Note: setting pagebreaks for a great whack of clients will take a while.

200 clients took 65 seconds on my 2.6Ghz Pentium 4


Gord Dibben Excel MVP


On Fri, 28 Jan 2005 08:53:03 -0800, Rob wrote:

I have a spreadsheet that has client numbers in the first column. I'd like to
be able to automatically put in page breaks for each client number. For
example, say rows 1 through 5 are client number 1, rows 6 & 7 are client
number 2, 8 through 15 are client 3 and so on. I'd like to have auto page
breaks at row 6, 8, 16, etc. Any ideas?


  #4   Report Post  
Gord Dibben
 
Posts: n/a
Default

Paul

I like this.

So very much much faster than the clunk I posted.

Thanks, Gord

On Fri, 28 Jan 2005 12:43:58 -0500, "Paul B"
wrote:

Rob, try this

Sub InsertBreaks()
Set rng = Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp))
For Each cell In rng
If Trim(cell.Value) < _
Trim(cell.Offset(-1, 0).Value) Then
ActiveSheet.HPageBreaks.Add cell
End If
Next
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Breaks fultanio Excel Worksheet Functions 5 March 17th 05 10:01 AM
How to add page breaks to embedded spreadsheet Lawrence Excel Worksheet Functions 0 January 18th 05 02:45 AM
Forcing page breaks Peter Cartwright Excel Discussion (Misc queries) 7 January 13th 05 03:03 AM
Page breaks don't show on screen and don't print separately. It i. Peter Excel Discussion (Misc queries) 1 November 29th 04 04:33 PM
How do I stop automatic page breaks in excel Lesley Hutchinson Excel Worksheet Functions 0 October 31st 04 12:49 PM


All times are GMT +1. The time now is 08:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"