Reputation: 11
I have one sheet with VBA code with many variables and constants and I would like to use those variables even in VBA code of another sheet. Unfortunately code is split between sheets and requires shared variables and constants as input parameters. Is it possible in VBA for excel?
Upvotes: 1
Views: 5383
Reputation: 86
Public token As String
can access from other sheets, here token is variable
Upvotes: 0
Reputation: 11161
Yes, you must declare variables as Public variable [As type]
. As @matzone said, at module level, i.e., before any subs, functions or properties.
In case of variable duplication you must refer to it as module.variable
, where module is module code name as Sheet1
or ThisWorkbook
.
Consider also the option of inserting a module in your VBA project to join all those shared variables (and functions, subs).
Upvotes: 1