Declaring Variables

B

BlairH

I'm either horribly confused, or old age is taking its toll. But there seems
to be too many options for declaring variables and I;m having trouble
figuring out the best way for declaring variables.

Tell me if I have it straight:

variables declared at the top of a module are shared within all procedures
in the module, decalred within a procedure/function are available to only
that procedure/function

variables declared Public are available to all modules
- in this workbook only or all workbooks?
- so these should be declared at the top of a module?

variables declared Static retain their values between procedure/function calls
- declare in a procedure/function

variables do not retain their values once hte code stops and control returns
to the user, so if you want to retain values you need to stor ethem in a cell
in the spreadsheet

Sound right?

Thanks!
 
J

Jackpot

I notice the specific question marks only now..Answers within brackets


- in this workbook only or all workbooks?
(In this workbook)

- so these should be declared at the top of a module?
(Yes)

variables declared Static retain their values between procedure/function calls
- declare in a procedure/function (Yes)


-variables do not retain their values once hte code stops and control
returns to the user, so if you want to retain values you need to stor ethem
in a cell
in the spreadsheet Sound right?

(Variables declared on top will retain their values all through that
Application session OR until Excel application is closed (assuming they are
not initialised within code))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top