Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Do loops within Do loops
Hi - I've written code that has 1 loop within another loop that is within yet
another loop - looks something like this: Do Do Do Loop Loop Loop It is not working though...just wanted to know if in theory a loop of this sort should work (assuming all other coding is correct). Thanks! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Do loops within Do loops
Yup that format is fine in general. The only problem is that it can be a
little tough to debug. That having been said there is often no good way around it. Check to ensure that each loop has an appropriate stop condition that can be met regardless of where it is in the processing of all of the loops... That is usually were the problem is and you end up in an infinite loop. HTH "Linking to specific cells in pivot table" wrote: Hi - I've written code that has 1 loop within another loop that is within yet another loop - looks something like this: Do Do Do Loop Loop Loop It is not working though...just wanted to know if in theory a loop of this sort should work (assuming all other coding is correct). Thanks! |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Do loops within Do loops
Thanks Jim!
"Jim Thomlinson" wrote: Yup that format is fine in general. The only problem is that it can be a little tough to debug. That having been said there is often no good way around it. Check to ensure that each loop has an appropriate stop condition that can be met regardless of where it is in the processing of all of the loops... That is usually were the problem is and you end up in an infinite loop. HTH "Linking to specific cells in pivot table" wrote: Hi - I've written code that has 1 loop within another loop that is within yet another loop - looks something like this: Do Do Do Loop Loop Loop It is not working though...just wanted to know if in theory a loop of this sort should work (assuming all other coding is correct). Thanks! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Do loops within Do loops
Would someone give an example of how to use a Stop condition? I'm still
working on conceptualizing vb[a]. "Jim Thomlinson" wrote: Yup that format is fine in general. The only problem is that it can be a little tough to debug. That having been said there is often no good way around it. Check to ensure that each loop has an appropriate stop condition that can be met regardless of where it is in the processing of all of the loops... That is usually were the problem is and you end up in an infinite loop. HTH |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Do loops within Do loops
Something needs to tell your code to stop looping - for example, it may
be a counter: Dim nCtr As Long nCtr = 0 Do nCtr = nCtr + 1 Loop Until nCtr 100 the "Until nCtr 100" is your "stop condition". Or you can use an Exit statement: Const sPWORD As String = "drowssap" Dim vResponse As Variant Do vResponse = Application.InputBox("Enter the Password") If vResponse = False Then Exit Sub 'user cancelled If vResponse = sPWORD Then Exit Do MsgBox "That's not correct" Loop there are a number of other conditions you can use. See the "Using Do...Loop Statements" topic in VBA Help. Note that you need to be careful to avoid an infinite loop. For instance, this will never exit: Dim nCtr As Long nCtr = 1 Do nCtr = nCtr + 2 Loop Until nCtr = 100 In article , "Nicole B" wrote: Would someone give an example of how to use a Stop condition? I'm still working on conceptualizing vb[a]. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
loops???? | Excel Worksheet Functions | |||
Using For - Next Loops in VB | New Users to Excel | |||
Do Loops | Excel Programming | |||
Do Loops | Excel Programming | |||
Loops | Excel Programming |