The efficient way to add multiple variables

variable with default initialized

The Variable Builder included in Code VBA is one of the tools that make specifying variables very easy and efficient.

  • If inside a procedure, you can indicate if you want the variable to appear at the cursor position or at the top of the procedure. The latter is useful in procedures with many variables where you want to be able to see them all together, possibly to check if you did not use different variables for the same thing;
  • If you want to declare multiple variables in one go it can do so using the Insert button which keeps the variable builder dialog open;
  • Chose to have default explicitly set (False in case of Boolean, "" for String, 0 for numerics);
  • You can switch from standard VBA types to select from types in the current Office application (here Excel).

Add variables to module header

private module header variable

You can also add variables to module header. You then can set the scope:

  • Public: also available to other modules.
  • Private: availability limited to the current module.

If no scope is set, Visual Basic assumes Public.