Repeating Structures
repetition structures are used to execute one or more instructions repeatedly
--------- Do ... Loop
allow us to execute a statement block for an unlimited number of times
* But while a condition is (TRUE) True or until you make real.
The sgte is an example of a macro that checks the condition is true at the beginning in order to continue with the repetitions
'first enter values \u200b\u200bin a column ... for example, A1 to A5
' now put yourself on cell A1 Sub
EJEMPLO_DO_LOOP () 'check condition at the beginning
' This macro adds the value of the variable "I"
'the value of each cell
' check the keyword While the condition is true '
and then continues execution
loop Dim I As Integer
Do While Not IsEmpty (Selection) 'continuran repeats as long as the selection' no 'is empty
I = I + 100
If IsNumeric (Selection) Then Selection.Value = Selection.Value + I
Selection.Offset (1, 0).
Select Loop End Sub
Sub EJEMPLO_DO_LOOP1 () ' final check
'This macro adds the value of the variable "I" to the value of each cell
' check the keyword While the condition is true but in the end is
'after you have run the loop at least once
Dim I As Integer Do
I = I + 100
If IsNumeric (Selection) Then Selection.Value = Selection.Value + I
Selection.Offset (1, 0).
Select Loop While Not IsEmpty (Selection) 'continuran repeats as long as the selection
' is not empty End Sub
0 comments:
Post a Comment