Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transient Subscript out of range error

Status
Not open for further replies.

Stoffel24

Technical User
Apr 4, 2002
121
ZA
I have a strange little error coming up here. I keep getting the message "Subscript out of range" when I execute the following code:
Range(Worksheets(1).HPageBreaks(Cnter).Location.Address).Select

The odd thing is when I run the following code:
Msgbox(Worksheets(1).HPageBreaks.count), I get a value of 3. The variable cnter has a value of 2, so there should be no problem. If I substitute the variable Cnter with the value 1, I have no problem, but if I put in a 2, I get the error again.

Even more odd is that if I step through the code, I don't get an error message. What is happening here?!! Any ideas.
I came across a similar problem at
thread707-244204 there was no solid solution.
 
I don't have any problems with this:
Code:
Function TestPBreak()
  Dim lngCtr As Long
  Dim lngMax As Long
  
  lngMax = ActiveSheet.HPageBreaks.Count
  
  For lngCtr = 1 To lngMax
    Range(ActiveSheet.HPageBreaks(lngCtr).Location.Address).Select
    Debug.Print Selection.Address
  Next
  
End Function
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
See thread707-395143 for a resolution to this problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top