Sunday, October 10, 2010

Icing Lips With Benadryl

in Excel VBA - I

control structures are lines of code with which you can change the program flow, such as decision-making structures such as If, if true perform certain actions over and over otherwise, or you can do nothing simply. We can divide the control structures such as repetition structures, decision structures. In this post I will explain about the structures of repetition.

The first structure we repeat:

1.

Loop For ... Next , with the following example will explain this step and helps to explain other things:


This example writes over the range A1: A10 Row number each one of them, this is done the loop uses the Value property of rg (i). In this loop there needs to be an accountant, in this case "i" and also a threshold indicating higher until the counter value is repeated. In this case the counter is increased by one. In the example the counter anger from 1 to rg.Count, rg.Count is the property that returns few cells have a range in this case 10.

In the example above, if we want to only enter the row number in the odd cells would have to go: 1,3,5,7 and 9. We see that the increase is 2 to 2. This is done by adding the keyword Step . In this example:


could also go backwards by For i = 10 to 1 Step -1

Finally a repeating structure that can be very useful when you want to search across a range of cells or a selection. For Each loop serves to scroll through a collection of objects excel. Generically:


Example, kill selected the range A1: A10 and B2: C14, run:


see that you have filled the numbers in all the selected cells. Selection In the example refers to the selected cell range as we can be a multiple selection.

2. Do loops

In general:



In the first form shown, first assess the condition and if true executes the code in C, therefore not necessarily be executed. Whereas the latter is executed at least once, the first, the third is an infinite loop condition. Consider the example:


In the example shown, the statements within the Do While, will run until i = 10. Similarly Until you use. Before concluding I will mention about keywords Exit For and Exit Do , these statements serve to terminate a loop or C respectively. Can be used say when a certain condition is fulfilled and is not necessary that the loop continues.

I hope you served. In the next post will explain about the structures of control If and Switch.

0 comments:

Post a Comment