ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Increment variable not incrementing? (https://www.excelbanter.com/excel-programming/317300-increment-variable-not-incrementing.html)

[email protected]

Increment variable not incrementing?
 
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?


[email protected]

Increment variable not incrementing?
 
Actually - its worse than I thought -

Now when I "watch" the process - its plowing right through the For-Next
loops without looping at all.


David

Increment variable not incrementing?
 
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


" wrote:

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?



[email protected]

Increment variable not incrementing?
 
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.



All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com