jwise
08-09-2007, 02:50 PM
Sorry folks. I can't find this anywhere.
For i = 1 to 20
If Cells(3, i) < 0 Then GoTo skip_it
.... ' processing
skip_it:
next i
OR_skip_it:
Hopefully, the above pseudo-code will give you an idea of what I am trying to do. Basically, I want to exit a loop early. Some languages get very upset if you branch outside a loop. The code listed has the disadvantage that it will go through iterations unnecessarily, i.e. once the "< 0" test fails, it will fail always (this is data dependent of course).
1. Could I use OR_skip_it as the destination in the "<0" test, or will VBA get upset?
2. Does vba have an "iterate" statement? This makes your code easier to read, and is probably more efficient.
3. Any restrictions on using the loop variable ("i" in this case) outside the loop?
4. Can I modify "i" inside the loop which alters the number of iterations? Does VBA get upset about this? For example, could I say "i = 21" to cause the immediate termination of the loop?
Thanks in advance
For i = 1 to 20
If Cells(3, i) < 0 Then GoTo skip_it
.... ' processing
skip_it:
next i
OR_skip_it:
Hopefully, the above pseudo-code will give you an idea of what I am trying to do. Basically, I want to exit a loop early. Some languages get very upset if you branch outside a loop. The code listed has the disadvantage that it will go through iterations unnecessarily, i.e. once the "< 0" test fails, it will fail always (this is data dependent of course).
1. Could I use OR_skip_it as the destination in the "<0" test, or will VBA get upset?
2. Does vba have an "iterate" statement? This makes your code easier to read, and is probably more efficient.
3. Any restrictions on using the loop variable ("i" in this case) outside the loop?
4. Can I modify "i" inside the loop which alters the number of iterations? Does VBA get upset about this? For example, could I say "i = 21" to cause the immediate termination of the loop?
Thanks in advance