Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

excel vba

ResolvedVersion 2003

Guangwen has attended:
Excel Advanced course
Excel VBA Intro Intermediate course

Excel VBA

How many different ways can variables be defined?

Edited on Thu 24 Jul 2008, 12:36

Variable Scope

Hi Guangwen

When declaring variables it must be remembered that there are 3 levels. They are:

Procedure-Level Variables

This is the most widely used variables. They are declared inside the Procedure itself (using the Dim keyword). Only the procedure that contains the variable declaration can use it. As soon as the Procedure finishes, the variable is destroyed.

Module-Level Variables

These are variables that are declared outside the Procedure itself in the Declarations section of a module (using the Dim keyword).

All variables declared at this level are available to all Procedures within the Module.

Public Variables

These variables are declared at the top of any standard Public module. Public variables are available to all procedures in all modules in a project

The Public keyword can only be used in the Declarations section

Hope this helps

Carlos

 

Training courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Generating Random Numbers

To generate a random number in Excel use the = RAND() function.

The value returned will always be between 0 and 1. To convert this to some other random value, you will need to multiply the result by the highest number you want to consider. For example, if you wanted a random number between 1 and 25, you could use the following code line:
= INT(25 * RAND()+ 1)

Since RAND() will always returns a value between 0 and 1 (but never 1 itself), multiplying what it returns by 25 and then using the Integer function INT on that result will return a whole number between 0 and 24.

Finally, 1 is added to this result, so that x will be equal to a number between 1 and 25, inclusive

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.