Updating For Loop statements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a For Loop in a VBA macro, for example:

b = 2
c = 26
For i = 1 To 10
For a = b To c
Print something in Excel using "a" (this bit is not important)
b = b + 25
c = c + 25
Next
Next

So that once the For Loop is complete the limits are updated for the next time inner For Loop is used. However, I find this when the inner For Loop is used for the second time "b" and "c" are reset to the values 2 and 26.

How can I get this to work?

Thanks.
 
Hi Stuart,

You're updating the variables in the wrong place. Try it like this:

b = 2
c = 26
For i = 1 To 10
For a = b To c
Print something in Excel using "a" (this bit is not important)
Next
b = b + 25
c = c + 25
Next


--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


stuart said:
Hi,

I have a For Loop in a VBA macro, for example:

b = 2
c = 26
For i = 1 To 10
For a = b To c
Print something in Excel using "a" (this bit is not important)
b = b + 25
c = c + 25
Next
Next

So that once the For Loop is complete the limits are updated for the next
time inner For Loop is used. However, I find this when the inner For Loop is
used for the second time "b" and "c" are reset to the values 2 and 26.
 

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