Pages

How to declare variables using variable scope

There are three types of variable levels:

  1. Procedure (used within a procedure)
  2. Module (used within a module and can be used with multiple procedures)
  3. Project ( used within a project and can be used with multiple modules)
For most vba you will need to declare variables. The "Dim" statement is used to setup your variables as different data types in conjunction with a variable name.

For example: Dim MyName as String

The example above uses the "Dim" statement, the variable name "MyName" and the data type of "String".

You can declare multiple variables of the same data type together.

For example: Dim MyName, MyAddress, MyCity, MyState, MyZip as String

You can also declare multiple variables of different data types together.

For example: Dim MyName as String, MySalary as Long, MyAge as Integer

Special Thanks to: