Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Changing a constant

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


--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Changing a constant

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 ???
--
HTH...

Jim Thomlinson


"achidsey" wrote:

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


--
achidsey

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Changing a constant

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????

achidsey wrote:

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


--
achidsey


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Changing a constant

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



"achidsey" (notmorespam) wrote in message
...
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


--
achidsey



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Changing a constant

But if you really want code to write code, you could use some of the information
at Chip Pearson's site:
http://www.cpearson.com/excel/vbe.htm

(This sounds like way too much work for the return (for me), though.)

achidsey wrote:

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


--
achidsey


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Changing a constant


Thanks very much for the responses. I think the input box would work well.

Alan


--
achidsey


"achidsey" wrote:

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


--
achidsey

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Constant loan payments vs. constant payments of principal lalli945 Excel Worksheet Functions 3 December 20th 06 10:33 PM
Constant sedonovan Excel Discussion (Misc queries) 5 June 23rd 06 11:43 AM
Constant? in VBA have_a_cup Excel Discussion (Misc queries) 1 June 14th 06 01:39 AM
Constant Warrio[_2_] Excel Programming 6 October 22nd 03 04:41 PM
Selecting a constant changing Range Michael[_10_] Excel Programming 2 August 14th 03 01:30 PM


All times are GMT +1. The time now is 11:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"