Excel VBA - changing variables during a loop

E

ellis_x

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
 
A

Auric__

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)
 
B

Bob Phillips

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)
 
Top