LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default variable number of For Next loops

One way is to use the If...ElseIf...Then statement:


If x = 2 Then
For i = 1 To 3
Range("A" & i) = i + 2
Next
ElseIf x = 3 Then
For i = 1 To 3
Range("A" & i) = i + 2
Next
For j = 4 T 10
Range("B1" & j) = j + 1
Next
End If

You could also use the Select Case. But the point is that you set a
criteria for VBA to evaluate. If the criteria is met, it does whatever is
behind the door that the criteria opens. If the criteria is not met, it
moves on to the nest executable line of code.



"KAH" wrote in message
...
Is there any way I can have a variable number of nested For ... Next
loops?
In other words, I want x loops. If x=2 there would be 2 loops, if x=3, 3
loops.

This is a follow-up to a question I posted May 29 about all permutations.
The answer I got was helpful and gave me ideas but didn't actually solve
my
problem. I realize what I really need to figure out is the variable number
of
loops.

Thanks for any help.



 
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
variable number of For Next loops Dave Peterson Excel Programming 0 June 10th 09 03:18 PM
Variable Step rates in loops gtslabs Excel Programming 2 February 16th 09 03:19 AM
Error Number: 91 object variable or With block Variable not set Hifni Excel Programming 1 January 9th 08 11:56 AM
variable string and loops Mourinho Excel Programming 2 October 27th 04 09:15 PM
Using a variable as a Row number Phil Hennessy Excel Programming 3 August 6th 04 05:56 PM


All times are GMT +1. The time now is 08:26 AM.

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

About Us

"It's about Microsoft Excel"