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?
2 Answers
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).