Hi all
I am having trouble with inserting manual page breaks
My code reads as follows:
Sub PageSetup()
'** Here we manually set a page break
Dim PgeBrk As Excel.HPageBreak
ActiveWindow.View = xlPageBreakPreview
For Each PgeBrk In Application.ActiveSheet.HPageBreaks
'Do stuff here and go to new location
Worksheets("Tensile-Bend"
.Rows(ActiveCell.Row + 1).PageBreak = xlPageBreakManual
Next PgeBrk
ActiveWindow.View = xlNormalView
End Sub
The problem is that even when there are several pages of data, when it gets to the part "For Each PgeBrk In Application.ActiveSheet.HPageBreaks" it gives me a subscript out of range error. If I return a count of HPagebreaks it returns 2 or 3 so we shouldn't be getting that error. Also, when I debug, I fiddle about but don't really change anything and then click on run again and it works - almost as if the first time round, it hadn't yet realised that there were a few pages of data.
Any ideas as to what is happening?
Thanks a lot.
I am having trouble with inserting manual page breaks
My code reads as follows:
Sub PageSetup()
'** Here we manually set a page break
Dim PgeBrk As Excel.HPageBreak
ActiveWindow.View = xlPageBreakPreview
For Each PgeBrk In Application.ActiveSheet.HPageBreaks
'Do stuff here and go to new location
Worksheets("Tensile-Bend"
Next PgeBrk
ActiveWindow.View = xlNormalView
End Sub
The problem is that even when there are several pages of data, when it gets to the part "For Each PgeBrk In Application.ActiveSheet.HPageBreaks" it gives me a subscript out of range error. If I return a count of HPagebreaks it returns 2 or 3 so we shouldn't be getting that error. Also, when I debug, I fiddle about but don't really change anything and then click on run again and it works - almost as if the first time round, it hadn't yet realised that there were a few pages of data.
Any ideas as to what is happening?
Thanks a lot.