For Each .. Next Repetition Structure (For .. Next Loops)
For ... Next structures those used in the cases when s know how many times it is necessary to repeat certain instructions
ejecuion
Sub obtener_los_56_colores ()
'here known that Excel handles a palette of 56 colors
'then we know also that it is necessary to repeat a certain section of code
As Byte Dim
Range ("A1: A56").
Select For a = 1 To 56' repeat 56 times
Selection.Cells (a). Interior.color = ActiveWorkbook.Colors (a)
'book assign colors to the respective cell to
Next End Sub
Sunday, April 20, 2008
I Get Thrush After Every Period
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
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
Subscribe to:
Posts (Atom)