vba variables
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA Variables

VBA Variables

resolvedResolved · Low Priority · Version 2003

replyReply Thu 14 May 2009, 16:40Delegate David said...

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?

For upcoming training course dates see: Pricing & availability

replyReply Mon 18 May 2009, 08:33Trainer Stephen said...

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.

 

Please browse our web site to find out more about
microsoft excel training courses and other Microsoft training courses.

Excel tip:

Bracketed negative numbers

Often Excel users wish to display negative numbers in colour red and bracketed

Intstructions
Step1. Select Format > Cells menu options. Within Numbers tabsheet, select Category = Custom.
Step 2. Select a type such as #,##0;[Red]-#,##0;; that specifies a colour in square brackets.
Step 3. Amend as follows; #,##0;[Red](#,##0;;

Notes: Excel formatting featues are of the form
"Positive; Negative;Zero;Text" separated by semicolon.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard