While programming in VBA sometimes you need to declare a Public Variable which can store the value through out the program.

Use of Public Variable : Let’s say you have 4 different Functions in your VBA Code or Module and you have a variable which may or may not be modified in any of the Functions during the execution. But whenever you want to use that variable, you want to latest value. In such case Public Variable is useful.

Public Variable must be defined under any Module. It can be defined under any Sheet Code. See the Syntax below:
Syntax: Public <Variable Name> As <Variable Type>

Public Variable

Public Variable


Join over 10, 000+ Excel VBA Enthusiasts & get this FREE e-Book Now!