how to use modules so that values calculated in one of them can beused by another?

  • Thread starter cagri mollamahmutoglu
  • Start date
C

cagri mollamahmutoglu

Basically i am trying to put all of subroutines which are under
thisworkbook section into different modules. for example if there are
sub1,sub2,sub3 under thisworkbook code window such that

sub0

call sub1

call sub2

endsub0

sub1
endsub1

sub2
end sub2

I want to write or move sub1 and sub2 into different modules such as
into module1 and module 2 respectively:

module1

sub1
end sub1

module2

sub1
end sub1

but the problem is when sub1 calculates and obtains a results and
assigns it to a variable which will be used in sub2 it is already
erased when module1 closes and module2 opens to call sub2. so the
question is what can I do so that the values which are assigned to
variables in a module are preserved or stick so they can be used by
other subs in other modules?
 
P

Patrick Molloy

read up on declaring variables and "scope"
Declare your variables at the top of the module and make them PUBLIC ...
this makes them available not onlyt to procedures in the module, but to
procedures in other modules.

OPTION EXPLICIT
PUBLIC MyVar as Variant
PUBLIC MiLong as Long
Sub mysub1()

End sub
 

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

Top