Named Constant

S

Shatin

Hi All,

If I have a named constant in a certain worksheet called "Status" whose
inital value is "On". What's the vba code for:

- finding out what the value of this named constant is?
- changing the value to "Off" if the value is "On"?

TIA
 
R

Ron Coderre

Try this:

To get the value:
Names("Status").RefersTo

To set the value:
Names("Status").RefersTo = "OFF"

Does that help?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)
 
J

Jim Thomlinson

A constant cannot be changed. That is the whole point to a constant. The
value remains constant no matter what. As a guess you are looking for a
global variable???

So instead of
Const MyVar as String = "On"
you want
Public MyVar as String

By default the string will be empty. You will need to initialize it prior to
using it.
 
J

Jim Cone

On the other hand...
If "Status" is truly a String Constant then its value will not change.
That is what "constant" means.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Shatin"
wrote in message
Hi All,
If I have a named constant in a certain worksheet called "Status" whose
inital value is "On". What's the vba code for:
- finding out what the value of this named constant is?
- changing the value to "Off" if the value is "On"?
TIA
 
R

Ron Coderre

You're very welcome, Shatin......I'm glad I could help.

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)
 

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