Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Page break code

Lets say I have an excel doc that has 6 colums and 1500 rows and
Column B is called file seq. I want a page break to happen everythime
the number in that row within that column is a 1. example Column B
has 10 rows 1.2.3.4.5.1.2.3.4.5.1 everytime 1 is there insert a
pagebreak.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Page break code


Option Explicit
Sub testme()
Dim wks As Worksheet
Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long

Set wks = ActiveSheet

With wks
.ResetAllPageBreaks 'maybe???
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
With .Cells(iRow, "A")
If .Value = 1 Then
.PageBreak = xlPageBreakManual
End If
End With
Next iRow
End With
End Sub


wrote:

Lets say I have an excel doc that has 6 colums and 1500 rows and
Column B is called file seq. I want a page break to happen everythime
the number in that row within that column is a 1. example Column B
has 10 rows 1.2.3.4.5.1.2.3.4.5.1 everytime 1 is there insert a
pagebreak.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Page break code


A slightly different solution using a For/Next loop. It works for me.

Sub InsertPageBreaks()

Dim FindRange As Range

With Sheets("Sheet1")
Set FindRange = .Range(.Range("B2"), .Range("B2").End(xlDown))
End With

Dim Cell As Object
Dim q As Long

Worksheets("Sheet1").ResetAllPageBreaks

For Each Cell In FindRange
If Cell.Value = 1 Then
q = Cell.Row
Sheets("Sheet1").Rows(q).PageBreak = xlPageBreakManual
End If

Next Cell

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
Excel 2007 Page Break Adjustments causes a page break each cell BKaufman Excel Worksheet Functions 2 September 10th 10 05:02 AM
VBA Code-listing page break John Wolcott Excel Programming 4 November 1st 08 02:34 AM
change and/or remove page number watermark in page break preview juga Excel Discussion (Misc queries) 2 December 25th 06 10:15 AM
adding a new page break to an existing page break Edward Letendre Excel Discussion (Misc queries) 1 March 6th 05 09:29 AM
Code to insert a Page Break Moore Excel Programming 2 August 6th 03 04:37 PM


All times are GMT +1. The time now is 08:42 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"