Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default 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)
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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/



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
finding the results of changing 4 variables irrhelp Excel Discussion (Misc queries) 4 June 19th 12 10:11 PM
Setting Multiple Variables with a loop jlclyde Excel Discussion (Misc queries) 6 November 11th 09 09:40 PM
Changing the values of variables mickiedevries[_6_] Excel Programming 0 June 23rd 04 07:48 PM
Loop for changing cell formatting Matt Excel Programming 1 January 15th 04 03:47 PM
Changing objects on other Worksheets with Variables Dave Baranas Excel Programming 3 August 10th 03 07:29 PM


All times are GMT +1. The time now is 07:05 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"