PC Review


Reply
Thread Tools Rate Thread

calling a routine to declare variables at start of macro

 
 
Michael
Guest
Posts: n/a
 
      12th Aug 2008
Hello all,

I have about 40 variables that I currently declare before running
about 5 macros. All of these are the same across the macros because
they set things like column numbers and start and end rows for the
spreadsheets I work with. The macros all reside in the same sheet.
How can I make it so that the variables all sit in one spot and are
referenced by the 5 different macros? Can I write a function that
declares the variables and then call that function in each of my 5
macros? I tried doing that but the macro did not recognize the
variables even after making them Public. Thanks!

Here is some sample code showing the variables I want to share across
the macros:
SP_Index = 3
SP_CA = 4
SP_WP = 5
etc...
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      12th Aug 2008
I'd create a new module that has this in it:

Option Explicit
Public VarsAreInitialized as Boolean
Public SP_Index as long 'or double or whatever
Public SP_CA as long
....

Sub InitializeVariables()
VarsAreInitialized = true
sp_index = 3
sp_ca = 4
...
End sub

Then in each of the routines that depend on those variables:

Option Explicit
Sub FirstSub()

if varsareinitilized then
'do nothing
else
call initializeVariables
end if

...rest of code
End sub



Michael wrote:
>
> Hello all,
>
> I have about 40 variables that I currently declare before running
> about 5 macros. All of these are the same across the macros because
> they set things like column numbers and start and end rows for the
> spreadsheets I work with. The macros all reside in the same sheet.
> How can I make it so that the variables all sit in one spot and are
> referenced by the 5 different macros? Can I write a function that
> declares the variables and then call that function in each of my 5
> macros? I tried doing that but the macro did not recognize the
> variables even after making them Public. Thanks!
>
> Here is some sample code showing the variables I want to share across
> the macros:
> SP_Index = 3
> SP_CA = 4
> SP_WP = 5
> etc...


--

Dave Peterson
 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      12th Aug 2008
On Aug 12, 1:52*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> I'd create a new module that has this in it:
>
> Option Explicit
> Public VarsAreInitialized as Boolean
> Public SP_Index as long 'or double or whatever
> Public SP_CA as long
> ...
>
> Sub InitializeVariables()
> * VarsAreInitialized = true
> * sp_index = 3
> * sp_ca = 4
> * ...
> End sub
>
> Then in each of the routines that depend on those variables:
>
> Option Explicit
> Sub FirstSub()
>
> * *if varsareinitilized then
> * * * 'do nothing
> * *else
> * * * call initializeVariables
> * *end if
>
> * *...rest of code
> End sub
>
>
>
>
>
> Michael wrote:
>
> > Hello all,

>
> > I have about 40 variables that I currently declare before running
> > about 5 macros. *All of these are the same across the macros because
> > they set things like column numbers and start and end rows for the
> > spreadsheets I work with. *The macros all reside in the same sheet.
> > How can I make it so that the variables all sit in one spot and are
> > referenced by the 5 different macros? *Can I write a function that
> > declares the variables and then call that function in each of my 5
> > macros? *I tried doing that but the macro did not recognize the
> > variables even after making them Public. *Thanks!

>
> > Here is some sample code showing the variables I want to share across
> > the macros:
> > * * SP_Index = 3
> > * * SP_CA = 4
> > * * SP_WP = 5
> > etc...

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


that worked great! thanks a bunch!!!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro calling another macro + variables =?Utf-8?B?eW8=?= Microsoft Excel Misc 2 5th Apr 2006 04:36 PM
where to declare variables John Salerno Microsoft C# .NET 5 14th Nov 2005 03:00 AM
Calling Macro - Will it take variables? Andibevan Microsoft Excel Programming 3 14th Jun 2005 03:28 PM
declare delegate inside routine: Possible? Mark Microsoft C# .NET 4 23rd Aug 2004 01:46 AM
Where to declare variables Harlan Microsoft Access Getting Started 1 20th Aug 2004 01:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:23 PM.