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

recording macro

ResolvedVersion 2003

Akiko has attended:
Excel VBA Intro Intermediate course

Recording Macro

I am not sure exactly when I should use

Edited on Thu 24 Jul 2008, 12:12

Variable Scope Dim vs Public

Hi Akiko

If you declare a variable as Dim it sets it up to be seen only by the procedure or module that contains it. For example:

Sub Test()

Dim MyName as String

MyName = "Carlos"

End Sub

If I wanted to access the value of MyName from another procedure it wouldn't find it.

So if the variable you are declaring needs to be accessible by all procedures and modules in a project then it needs to be declared as Public. For example:

Public MyName as String

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:

Apply currency format quickly in Excel

To quickly apply the currency format to cell in your spreadsheet, select (highlight) the cells you wish to apply currency format to, then use Ctrl + Shift + $

This will apply a pounds symbol even though the $ key is pressed.

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.11 secs.