View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Taras Taras is offline
external usenet poster
 
Posts: 14
Default Best place to declare variables

Bill,
Thanks for your input.

I think that as long as I ensure I initialize the
variable in the first sub that I use it in, I should be
OK.

What is your opinion on declaring the variables in a sub
that is executed when the spreadsheet is opened so that
they would be available to any macro following.

The sheet is rarely used without running some macro.
Taras
-----Original Message-----
Taras wrote:
Is it more efficient to declare the variables with DIM

in
Module A & Module B or to declare them as Public
elsewhere?


Module-level variables (whether Public or not) have

space permanently
allocated. So having 2 sets will consume twice as much

space.

However, I would not advocate using Public variables in

case you end up
changing the sequence in which things are done and get

conflicting
usage of the same variable between procedures in

different modules.


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup

.