Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Can someone explain what a While loop and a For loop is and
demonstrate an example ogf how it could be used in VBA. As i am struggling to understand the concept and example of it in use please thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
A For and a While loop is used to repeat an action a number of times,
changing the object being acted upon, or until a set number of actions has been performed. For instance, you could select a range of cells in Excel, then this code For each cell in Selection cell.Interior.ColorIndex = 3 Next cell will set the cell colour of each cell to 3. You can also use an index counter in a loop, like so For i = 1 To Selection.Rows.Count Step 2 Selection.Cells(i, 1).Interior.ColorIndex = 3 Next i colours very other row of the first column. While loops are similar, where you test while a condition is true, but are not used as much. -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "paul" wrote in message ps.com... Can someone explain what a While loop and a For loop is and demonstrate an example ogf how it could be used in VBA. As i am struggling to understand the concept and example of it in use please thanks |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"paul" wrote...
Can someone explain what a While loop and a For loop is and demonstrate an example ogf how it could be used in VBA. As i am struggling to understand the concept and example of it in use Read other people's code. This ng would be a good place to start. If you want a dictionary explanation, For loops are used when you know in advance how many iterations you want to perform. [Do] While (and Do Until) loops are used when you know the continuation (or stopping) criteria but not necessarily the number of iterations needed. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Loops & Ifs | Excel Programming | |||
Loops | Excel Programming | |||
for each loops | Excel Programming | |||
LOOPS | Excel Programming | |||
Loops | Excel Programming |