By Hemanta Sundaray on 2021-09-05
In VBA, we can declare variables using a Dim statement.
Dim revenue As Long
If the above statement appears inside a procedure, the variable revenue can only be used in that procedure.
If the statement appears in the Declarations section of the module, the variable revenue is available to all procedures in the module, but not to procedures in other modules of the project.
If we don’t specify a data type, the Variant data type is assigned by default.
We can also declare several variables in one statement:
Dim revenue As Long, profit As Long
We can make a variable available to all procedures in the project by preceding it with the Public statement.
Public revenue as Long
We can declare variables that can only be used by procedures in the same module using the Private statement.
Private MyName As String