Increment variable not incrementing?

  • Thread starter Thread starter marston.gould
  • Start date Start date
M

marston.gould

I have a series of loops that utilize the same set of variables
as integer increments...

For i = 1 to 100
For j = 1 to 200
..
..
..
Next j
Next i
For i = 1 to 500
..
..
..


The odd thing is that when it hits the subsequent use of the variable
in next set of for/next loops, the variable is not resetting to the
value called for in the loop. What I see happening is that its starting
off at 1+ the top value of the prior loop. So in this instance, it
would start at 101 and go to 500.

Thoughts?
 
Actually - its worse than I thought -

Now when I "watch" the process - its plowing right through the For-Next
loops without looping at all.
 
This works, need to change numbers
Sub Macro7()
For i = 1 To 2
For j = 1 To 2
Stop
Next j
Stop
Next i
End Sub
 
Actually, it was a much different problem.

What I discovered was that I had dim'd the counters as Integers, but on
one occasion,
it just happened the upper bound of the 2nd use of the counter happened
to be larger than 32,767 (the upper limit of an integer) and so the
code was just pushing through the For Next loop ignoring the For and
the Next. Once I changed the Integer statement to Long, it worked fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top