#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8
Default loops????

can nay one help as 2 what a while and for a for loop does in vba?

and what are the syntaxes for these?

also could any1 demonstrate how this would work in a section of code
becasue there are so many types of loops and im gettinmg confused

please help

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 772
Default loops????

There are basically 3
A Do While does while something is true as in
Do While myValue=True
stuff
Loop
it will do the code (stuff) until something changes myValue to False

There is a Do Until which is kind of the opposite
Do Until myValue=False
stuff
Loop
This is the one I use most often, do something until cells are blank is most
common

and For Next is for when you know how many times to do something
For i = 1 To sheets.count
stuff
Next
This is one used often as well, the one above sets a base of 1 and does
something for however many sheets there are. Handy because you can step
forward backward 2 at a time etc.

All really depends on your situation but you can almost always pick any of
the 3 and make it suit your needs.

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"harry buggy" wrote:

can nay one help as 2 what a while and for a for loop does in vba?

and what are the syntaxes for these?

also could any1 demonstrate how this would work in a section of code
becasue there are so many types of loops and im gettinmg confused

please help


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default loops????

Just for completeness sake, there are two other loop formats..

Do
Stuff
Loop While <<logical test

and

Do
Stuff
Loop Until <<logical test

The difference between these forms and their Do While/Until counterparts is
that the Loop While/Until versions will always execute the Stuff statements
at least one time because the exit condition isn't tested until the end of
the loop.

Rick


"John Bundy" (remove) wrote in message
...
There are basically 3
A Do While does while something is true as in
Do While myValue=True
stuff
Loop
it will do the code (stuff) until something changes myValue to False

There is a Do Until which is kind of the opposite
Do Until myValue=False
stuff
Loop
This is the one I use most often, do something until cells are blank is
most
common

and For Next is for when you know how many times to do something
For i = 1 To sheets.count
stuff
Next
This is one used often as well, the one above sets a base of 1 and does
something for however many sheets there are. Handy because you can step
forward backward 2 at a time etc.

All really depends on your situation but you can almost always pick any of
the 3 and make it suit your needs.

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"harry buggy" wrote:

can nay one help as 2 what a while and for a for loop does in vba?

and what are the syntaxes for these?

also could any1 demonstrate how this would work in a section of code
becasue there are so many types of loops and im gettinmg confused

please help



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 [email protected] Excel Discussion (Misc queries) 2 October 14th 06 02:52 PM
Loops... Willabo Excel Discussion (Misc queries) 2 June 14th 06 04:08 PM
do loops saravanan Excel Worksheet Functions 0 June 13th 06 10:53 AM
For next loops Kate Excel Discussion (Misc queries) 5 May 22nd 06 01:11 PM
Using For - Next Loops in VB Biomed New Users to Excel 4 March 22nd 05 07:12 PM


All times are GMT +1. The time now is 08:40 PM.

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"