98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA Variables
VBA Variables
Resolved · Low Priority · Version 2003
David has attended:
Excel VBA Intro Intermediate course
Excel VBA Advanced course
VBA Variables
I sometime set up the same variable (Dim) in 2 modules which then cause errors when i call procedures between them. When I do this, are there any quick ways to spot which variable is causing the problem?
RE: VBA Variables
Hi David
Thank you for your question
The version of a variable used by a procedure will usually be the one "most local" to the code.
If a variable is used in a procedure, the code first searches in that procedure for a variable of that name, and uses it if it is there. if not then it will search for dim declared variables in the declarations section of the module, and failing that for public variables in any other module. It will always use the first one it finds.
In the example you give, simply look for the variable "most local" to the line of code. It is however, a good idea not to use duplicate variable names for module and procedure level variables
Regards
Stephen
Tue 26 May 2009: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Finding cells that have data restrictionsClick anywhere on the worksheet. |