Changing a constant

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Excel Experts,

I use a constant throughout a module of code.

I specify it with the following line of code at the top of the module:

Const CurDay As String = "Day1"

Currently, I go into the module and modify it changing Day1 to Day2, etc.

Now I am creating a user interface so others can run my code. I've created
command buttons in a spreadsheet so users don't have to go to the module
level.

My question: Is there code that will alter the value of my constant CurDay?
Specifically I want to write code that says

Change the line
Const CurDay As String = "Day1"
to
Const CurDay As String = "Day2"

How would I do this?

Thanks in advance,
Alan
 
That one you really can't do. A constant is just that... constant. No matter
what, you can always count on it to be the same from beginning to end... What
you really want is a global variable. Change const to public, remove the "=
"Day 1" and so long as it is in a standard module you have a beginning. You
will need to initialize it when the spreadsheet is first opened (you can use
the on open event for this). It can grab the value from a cell or ???
 
Maybe it would be better to just declare CurDay as a variable.

Dim CurDay as String
....

Then get the value for that variable some other way--maybe an inputbox???

curday = inputbox(Prompt:="Please enter the Current Day value")

or maybe you could determine that value some other way????
 
By definition, you can't change constant values. You'd have to
make it a public (global) variable.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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

Similar Threads


Back
Top