Access to Variable

  • Thread starter Thread starter C Brandt
  • Start date Start date
C

C Brandt

Here's a very basic question that I'm embarassed to ask, but nothing
ventured, nothing gained.
The cause of my problem stems from the lack of understanding the whole
archectecture of environments.
I create a procedure and it seems as though I have no control of where it
goes. Sometimes they get nestled together, separated by a simple line and
othertimes I have to go back to the menu and specifically select the next
module.
More important, is that when I create and fill a variable in one routine,
even if it is declared (by default) as a Public, I cannot seem to use it in
the next routine.

Can someone direct me to a good place to start looking to get a better
understanding of this subject matter.

Thanks in advance,
Craig
 
You might start by reading the responses to this discussion:
http://www.microsoft.com/office/com...ca5f37-0457-460a-b129-7a4132ff8304&sloc=en-us

Just to give you a kick-start, there are 4 places in an Excel workbook that
code can be located:
#1 - code modules not associated with the workbook/worksheets (can be
referenced from more specific code areas)
#2 - code associated with the workbook events
#3 - code associated with woksheet events (one for each worksheet)
#4 - code associated with UserForms

A Public variable/constant to be accessed from anywhere at all must be
declared in one of the #1 type code modules and it must be declared outside
of a Sub or Function. So those Public values would be at the very beginning
of the module, before any Sub or Function code in it.

If you declare a variable/constant with the same name as a Public one, then
the one declared within the Sub/Function will be used instead of the Public
one. This is all about 'scope'. So you may want to focus on that subject in
your initial reading.

Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top