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

I found this code in the forum for applying a page break at every 50 rows of
data and I changed it to 17 rows. The problem is, is that it applies not only
a horizontal but also a verticle page break. The other issue is that it
applies the horizontal one at row 21 and not at 17. Why??

Sub setPage()
Dim iRow As Long
Dim myCell As Range
Dim myRng As Range
Dim wks As Worksheet
Dim searchFor As String

searchFor = FrmCreate.CbxDept.Text
Set wks = Worksheets(searchFor)
With wks
.ResetAllPageBreaks
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) _
.Cells.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "No visible cells!"
Exit Sub
End If

iRow = 0
For Each myCell In myRng.Cells
iRow = iRow + 1
If iRow 1 Then
If iRow Mod 17 = 1 Then
.HPageBreaks.Add befo=myCell
Call FormatHeaders
End If
End If
Next myCell
End With

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Page break issues

I think you're seeing a natural vertical page break--the code isn't adding any.

And this code was used with data that was filtered--some of the rows were
hidden. The original poster only wanted ## number of visible rows per printed
page.

I'm guessing that you have some hidden rows.

Mekinnik wrote:

I found this code in the forum for applying a page break at every 50 rows of
data and I changed it to 17 rows. The problem is, is that it applies not only
a horizontal but also a verticle page break. The other issue is that it
applies the horizontal one at row 21 and not at 17. Why??

Sub setPage()
Dim iRow As Long
Dim myCell As Range
Dim myRng As Range
Dim wks As Worksheet
Dim searchFor As String

searchFor = FrmCreate.CbxDept.Text
Set wks = Worksheets(searchFor)
With wks
.ResetAllPageBreaks
Set myRng = Nothing
On Error Resume Next
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) _
.Cells.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "No visible cells!"
Exit Sub
End If

iRow = 0
For Each myCell In myRng.Cells
iRow = iRow + 1
If iRow 1 Then
If iRow Mod 17 = 1 Then
.HPageBreaks.Add befo=myCell
Call FormatHeaders
End If
End If
Next myCell
End With

End Sub


--

Dave Peterson
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
Page Break Issues Karin Excel Discussion (Misc queries) 0 January 12th 10 10:23 PM
Page break issues Gibbie Excel Discussion (Misc queries) 1 July 8th 09 07:48 PM
How do I do page breaks when view menu doesnt page break preview HeatherF55 Excel Discussion (Misc queries) 0 September 21st 07 04:24 AM
adding a new page break to an existing page break Edward Letendre Excel Discussion (Misc queries) 1 March 6th 05 09:29 AM


All times are GMT +1. The time now is 01:58 AM.

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"