Increment Variable Expansion

Several programming languages use the ++ statement as a short-hand for incrementing a variable by one. VbaPrime emulates this feature by expanding varName++ to varName = varName + 1


Using the increment operator ++ has the following advantages:

  • it is significantly quicker than having to type the variable name twice.
  • it more clearly follows the programmer's intent.
  • it is more familiar to developers of C-based languages.


The following animation demonstrates the ++ and -- operators being expanded to VBA addition and subtraction statements.


Perform the following steps to see ++ automatically expanded:

  1. Open the Visual Basic Editor (VBE) and double-click on a module to open up its code window.
  2. Type Sub MySub() into the code window and then press enter. The VBE will automatically add the End Sub statement.
  3. Type myVar++, then press enter.
  4. VbaPrime will replace the myVar++ statement with myVar = myVar + 1, then place the cursor on the next line.


VbaPrime handles the decrement operator -- in the same manner.