Sunday, December 31, 2017

How to loop a macro in VBA

Dim I
For I = 1 to 20
your code here
Next I



Goto Instruction

Syntax

GoTo label

Group

Description

Go to the label and continue execution from there. Only labels in the current user defined procedure are accessible.

Example


Sub Main 
X = 2 
Loop: 
X = X* 
If
 X < 100 Then GoTo Loop 
Debug
.Print X ' 256 
End Sub

No comments: