Procedure Level Local Variables

From this chapter, you already know how to declare a variable by using the Dim keyword. The position of the Dim keyword in the module sheet determines the scope of a variable. Variables declared with the Dim keyword placed within a VBA procedure have a procedure-level scope.

Procedure-level variables are frequently referred to as local variables. Local variables can only be used in the procedure where they were declared. Undeclared variables always have a procedure-level scope.

A variable's name must be unique within its scope. This means that you cannot declare two variables with the same name in the same procedure. However, you can use the same variable name in different procedures. In other words, the CalcCal procedure can have the slsTax variable, and the ExpenseRep procedure in the same module can have its own variable called slsTax. Both variables are independent of each other.

0 0

Post a comment