Hi all
I have a bizarre problem. The following code runs fine on most machines but on a few, it gives me a subscript out of range error at the line that is red. I added the following watch to see what value was coming through: "Worksheets("Tensile-Bend"
.HPageBreaks.Count"
This showed me that on the machine where there is no problem, this watch remains constant at 8. However, on the machines where the code doesn't work, the value changes, starting initially at 15. The values in the square brackets represent the value of the watch on the machines where the code works and where it doesn't respectively. Notice how it goes 15, 17 and then critically and inexplicably, 1!
Sub PageSetup()
'** Here we manually set a page break and place column headings in.
Dim Rw As Integer
Dim Found As Boolean, Cnter As Integer, Cnter2 As Integer
Dim Rwnext As Integer
ActiveWindow.View = xlPageBreakPreview '[8, 15]
For Cnter = 1 To Worksheets("Tensile-Bend"
.HPageBreaks.Count '[8, 17]
Found = False '[8, 1]
Range(Worksheets("Tensile-Bend"
.HPageBreaks(Cnter).Location.Address).Select
'** Do a whole bunch of things here.
Next
ActiveWindow.View = xlNormalView
End Sub
Because Excel determines there is only one page break AFTER the "For Cnter = ..." step, when we get to the loop where Cnter = 2 the line "Range(Worksheets("Tensile-Bend"
.HPageBreaks(Cnter).Location.Address).Select" gives us Subscript out of range message. I have tried putting in a line like "BrkCnt = Worksheets("Tensile-Bend"
.HPageBreaks.Count" after the "For Cnter = ..." line but this seems to have no effect. [Ponder] "Come on Scott throw me a frikin' bone here."
I have a bizarre problem. The following code runs fine on most machines but on a few, it gives me a subscript out of range error at the line that is red. I added the following watch to see what value was coming through: "Worksheets("Tensile-Bend"
This showed me that on the machine where there is no problem, this watch remains constant at 8. However, on the machines where the code doesn't work, the value changes, starting initially at 15. The values in the square brackets represent the value of the watch on the machines where the code works and where it doesn't respectively. Notice how it goes 15, 17 and then critically and inexplicably, 1!
Sub PageSetup()
'** Here we manually set a page break and place column headings in.
Dim Rw As Integer
Dim Found As Boolean, Cnter As Integer, Cnter2 As Integer
Dim Rwnext As Integer
ActiveWindow.View = xlPageBreakPreview '[8, 15]
For Cnter = 1 To Worksheets("Tensile-Bend"
Found = False '[8, 1]
Range(Worksheets("Tensile-Bend"
'** Do a whole bunch of things here.
Next
ActiveWindow.View = xlNormalView
End Sub
Because Excel determines there is only one page break AFTER the "For Cnter = ..." step, when we get to the loop where Cnter = 2 the line "Range(Worksheets("Tensile-Bend"