Store variables in code just as you can w. constants? Available to read/edit?

T

tskogstrom

Hi,
Constants can be set, but is there a way to change them dynamically
when needed, during the work in the workbook? To be used as variables
instead?

I want to store a number of ranges (actually, number of areas) and
have earlier tried to use "cell.value = [range].address" stored in
worksheet cells, but have stranded in that approach and search after
another way.

Best would be if they are accessible from all modules & subs, if
possible.

Kind regards
Tskogstrom
 
L

Leith Ross

Hi,
Constants can be set, but is there a way to change them dynamically
when needed, during the work in the workbook? To be used as variables
instead?

I want to store a number of ranges (actually, number of areas) and
have earlier tried to use "cell.value = [range].address" stored in
worksheet cells, but have stranded in that approach and search after
another way.

Best would be if they are accessible from all modules & subs, if
possible.

Kind regards
Tskogstrom

Hello Tskogstrom,

Not sure why you can't use a variable, but that is what you are
describing. A constant's value is fixed during the compilation
process. By definition a constant doesn't change. To make it
accessible to all modules an proceduresn declare the constant or
variable in a Standard VBA Module using the keyword "Public". If you
need this to be seen by Class Modules also, use the "Global" keyword.

Sincerely,
Leith Ross
 
B

Bob Phillips

Just use public variables declared at the start of a standard code module.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
B

Bob Phillips

Global?

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



Leith Ross said:
Hi,
Constants can be set, but is there a way to change them dynamically
when needed, during the work in the workbook? To be used as variables
instead?

I want to store a number of ranges (actually, number of areas) and
have earlier tried to use "cell.value = [range].address" stored in
worksheet cells, but have stranded in that approach and search after
another way.

Best would be if they are accessible from all modules & subs, if
possible.

Kind regards
Tskogstrom

Hello Tskogstrom,

Not sure why you can't use a variable, but that is what you are
describing. A constant's value is fixed during the compilation
process. By definition a constant doesn't change. To make it
accessible to all modules an proceduresn declare the constant or
variable in a Standard VBA Module using the keyword "Public". If you
need this to be seen by Class Modules also, use the "Global" keyword.

Sincerely,
Leith Ross
 

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