PDA

View Full Version : Declaring variables publically



Djblois
08-01-2006, 01:56 PM
I have a macro that runs many othe macros to perform many function. I declare a lot of variables publically. Does it slow things down? Should I declare the variables only as I need them? I don't Set them yet just declare them.

Bob Phillips
08-01-2006, 02:43 PM
I think it is safe to say that you should limit the scope of variables as much as possible. Keep them to macro level where possible, then module level, and then global. Maybe even consider creating classes with variables as properties.

Djblois
08-01-2006, 04:36 PM
I think it is safe to say that you should limit the scope of variables as much as possible. Keep them to macro level where possible, then module level, and then global. Maybe even consider creating classes with variables as properties.

How do you create classes? with variables as properties?
I am new and trying to learn so be easy on me with your explanation. I am a Excel power user but new to VBA, at least when it comes to writing my own code.

Bob Phillips
08-02-2006, 01:02 AM
Chip Pearson has a page on it at http://www.cpearson.com/excel/ClassModules.htm