For-Next Autocompletion


All For statements must be followed by a Next statement. VbaPrime will automatically add the corresponding Next statement when you finish typing the For statement.


The following animation demonstrates the End If being automatically added, and the cursor being placed on the line between.


Perform the following steps to see VbaPrime complete a For-Next combination.

  1. Open the Visual Basic Editor (VBE) and double-click on a module to open up its code window.
  2. Type Sub TestSub() and then press enter. The VBE will automatically add the End Sub statement and place the cursor between them.
  3. Now type For i = 1 to 10, then press the enter key.
  4. Observe that VbaPrime automatically enters the Next i statement and places the the cursor above it. VbaPrime also indents the code by one tab.

Automatic Variable Detection

VbaPrime will find the intrinsic variable in your For statement and add it to the Next statement. For example , VbaPrime added i in the example section above.

Existing Code

When you press the enter key, VbaPrime will check to see if there is already a Next statement that corresponds to the For statement. If there is a Next, VbaPrime will not add any code. This feature prevents spurious Next statements being added as you navigate around existing code.