Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Updating For Loop statements

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Updating For Loop statements

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" wrote in message
...
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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Too Many IF Statements Nesting Error (Excel Formula Loop w/o VBA) retailmessiah[_2_] Excel Worksheet Functions 7 February 10th 10 06:52 PM
Need loop structure to get round limited IF statements karambos Excel Discussion (Misc queries) 5 August 30th 05 12:31 AM
When updating a worksheet, how do I create a link updating the sa. Phlashh Excel Worksheet Functions 9 January 27th 05 06:05 PM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 08:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"