Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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
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
loops???? harry buggy Excel Worksheet Functions 2 August 14th 07 06:33 PM
Using For - Next Loops in VB Biomed New Users to Excel 4 March 22nd 05 07:12 PM
Do Loops No Name Excel Programming 1 July 20th 04 04:47 PM
Do Loops Sue[_5_] Excel Programming 1 May 20th 04 07:51 PM
Loops PaulSinki Excel Programming 3 December 10th 03 05:01 PM


All times are GMT +1. The time now is 12:48 AM.

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"