Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use modules so that values calculated in one of them can beused by another?

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default how to use modules so that values calculated in one of them can be

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

"cagri mollamahmutoglu" wrote:

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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
retaining variable values across modules c1802362[_2_] Excel Programming 3 March 10th 09 03:56 AM
Calculated Values ssoerens Excel Worksheet Functions 2 July 25th 07 04:26 AM
Loosing values when working on different functions and modules.. SupperDuck Excel Programming 3 July 9th 07 01:50 AM
There must be a way!!!--set cells' values equal to calculated values in another range Arnold[_3_] Excel Programming 8 January 1st 07 10:32 PM
Exporting calculated values Susan Setting up and Configuration of Excel 2 September 11th 06 06:27 PM


All times are GMT +1. The time now is 04:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"