Repeats a group of statements a specified number of times.
For I = 1 to 50 Step 2 A = I * 2 Debug.Print A Next I
For I = 50 to 1 Step -2 A = I * 2 Debug.Print A Next I
In this example, the variable I initializes at 1 and, with each iteration of theFor/Next loop, is incremented by 2 (Step). This looping continues until I becomesgreater than or equal to its final value (50). If Step is not included, the default valueis 1. Negative values of Step are allowed. · You may exit a For/Next loop using an Exit For statement. This will transferprogram control to the statement following the Next statement.
The single most important practice for writing clear, decipherable code is to add frequent comments.Comments are lines in your code which act as notes to yourself or others, to explain what the code means or what it is doing. Comments are not executed during the running of the program, so have no impact on the result your macro. VBA considers any line that starts with an apostraphe (') to be a comment and the Excel VBA editor highlights these lines by colouring them in green, so you can see, at a glance, that they are comments and will not be executed.See the example below, which shows comments used to clarify the details of a simple subroutine:' Subroutine to search cells A1-A100 of the current active
' sheet, and find the cell containing the supplied string Sub Find_String(sFindText As String)
Dim i As Integer' Integer used in 'For' loopDim iRowNumber As Integer' Integer to store result in
iRowNumber = 0