![]() |
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? |
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? |
All times are GMT +1. The time now is 01:07 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com