ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA - changing variables during a loop (https://www.excelbanter.com/excel-programming/303248-excel-vba-changing-variables-during-loop.html)

ellis_x[_3_]

Excel VBA - changing variables during a loop
 
Hi,

I am trying to write a loop code using the For...Next statements, for
counter running from 1 To 100. However, I want to change the value o
two of the variables (there are 5 used in the procedure) after counte
= 10, then again at 20, 30, and so on.

I have not been able to figure out how to do this without repeating th
code with the new value for the variable re-defined.

Has anyone got any ideas of how to overcome this problem?

Cheer

--
Message posted from http://www.ExcelForum.com


Auric__

Excel VBA - changing variables during a loop
 
On Mon, 5 Jul 2004 02:13:34 -0500, ellis_x
wrote:

Hi,

I am trying to write a loop code using the For...Next statements, for a
counter running from 1 To 100. However, I want to change the value of
two of the variables (there are 5 used in the procedure) after counter
= 10, then again at 20, 30, and so on.

I have not been able to figure out how to do this without repeating the
code with the new value for the variable re-defined.

Has anyone got any ideas of how to overcome this problem?

Cheers


If the same thing always happens to those variables (for example, you
always add 1 or something) then a simple if statement should do it:
If (0 = counterVariable Mod 10) Then
'make changes here
End If

If it's a different action each time, then try select case:
Select Case counterVariable
Case 10
'make changes here
Case 20
'make changes here
Case 30
'make changes here
[etc.]
End Select

--
auric underscore underscore at hotmail dot com
*****
You can't exchange pleasantries with an attractive woman and feel
entirely like a stranger.
-- Isaac Asimov (Prelude to Foundation)

keepITcool

Excel VBA - changing variables during a loop
 
for i=1 to 100
if i mod 10 = 0 then j=1
next


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


ellis_x wrote:

Hi,

I am trying to write a loop code using the For...Next statements, for a
counter running from 1 To 100. However, I want to change the value of
two of the variables (there are 5 used in the procedure) after counter
= 10, then again at 20, 30, and so on.

I have not been able to figure out how to do this without repeating the
code with the new value for the variable re-defined.

Has anyone got any ideas of how to overcome this problem?

Cheers


---
Message posted from http://www.ExcelForum.com/




Bob Phillips[_6_]

Excel VBA - changing variables during a loop
 
For i = 10 To 100 Step 10
....
Next

???

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"ellis_x " wrote in message
...
Hi,

I am trying to write a loop code using the For...Next statements, for a
counter running from 1 To 100. However, I want to change the value of
two of the variables (there are 5 used in the procedure) after counter
= 10, then again at 20, 30, and so on.

I have not been able to figure out how to do this without repeating the
code with the new value for the variable re-defined.

Has anyone got any ideas of how to overcome this problem?

Cheers


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 11:27 AM.

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