I should have said that the code didn't cause an error. It didn't actually do
what you wanted.
But this may help:
Option Explicit
Sub hpb2()
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
With Worksheets(1)
.ResetAllPageBreaks
FirstRow = 36
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For iRow = FirstRow To LastRow Step 35
.HPageBreaks.Add Befo=.Cells(iRow, "A")
Next iRow
End With
End Sub
Dave Peterson wrote:
I copied that code and it worked ok for me.
What was the line that caused the error?
btm wrote:
NickHK,
I tried that line of code but I get an error message "Expected: =".
Below is a simplified example of what I'm trying to do. I want to add
pagebreaks every 35 rows.
Sub hpb()
hpbCnt = 0
hpbrow = 0
Worksheets(1).PageSetup.PrintArea = "$A$1:$D$500"
Dim cell As String
Do While hpbCnt < 500
hpbrow = hpbrow + 35
hpbCnt = hpbCnt + 1
cell = "d" & CStr(hpbrow)
Worksheets(1).HPageBreaks(1).Location = Worksheets(1).Range(cell)
Loop
End Sub
btm
--
btm
------------------------------------------------------------------------
btm's Profile: http://www.excelforum.com/member.php...o&userid=24880
View this thread: http://www.excelforum.com/showthread...hreadid=384229
--
Dave Peterson
--
Dave Peterson