#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Constants


I store some values in "Names"
EG Names "Site1" to "Site10" store 10 locations such as "Site1" = Bolton
"Site2" = Chorley Etc
I can retrieve them like this

Sub SetNames()
Dim Ctr as Byte
For Ctr = 1 to 10
Range("A" & Ctr) = Application.Evaluate("Site" & Ctr)
Next
End Sub

I have tried storing the values in Constants but I cannot retrieve them in
the same way as shown above. I have to write a seperate line of code for each
Constant.
Please could anyone show me a way to use a group of 10 Constants in the same
way as I have used the 10 values stored in Names.

Thankyou in anticipation
--
Roger
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Constants


Constants are Constant. There are not meant to be changed by the software.

"Roger" wrote:

I store some values in "Names"
EG Names "Site1" to "Site10" store 10 locations such as "Site1" = Bolton
"Site2" = Chorley Etc
I can retrieve them like this

Sub SetNames()
Dim Ctr as Byte
For Ctr = 1 to 10
Range("A" & Ctr) = Application.Evaluate("Site" & Ctr)
Next
End Sub

I have tried storing the values in Constants but I cannot retrieve them in
the same way as shown above. I have to write a seperate line of code for each
Constant.
Please could anyone show me a way to use a group of 10 Constants in the same
way as I have used the 10 values stored in Names.

Thankyou in anticipation
--
Roger

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Constants


Hi Roger

Do you mean something like the below. Insert a module and copy the code and
try. You can append more data to the string variable with a comma separator


Public Const strLocation As String = "loc1,loc2,loc3,loc4,loc5"

Sub Macro()
Dim arrLocation As Variant
arrLocation = Split(strLocation, ",")
MsgBox arrLocation(0) 'To access location1
MsgBox arrLocation(1) 'To access location2

End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Roger" wrote:

I store some values in "Names"
EG Names "Site1" to "Site10" store 10 locations such as "Site1" = Bolton
"Site2" = Chorley Etc
I can retrieve them like this

Sub SetNames()
Dim Ctr as Byte
For Ctr = 1 to 10
Range("A" & Ctr) = Application.Evaluate("Site" & Ctr)
Next
End Sub

I have tried storing the values in Constants but I cannot retrieve them in
the same way as shown above. I have to write a seperate line of code for each
Constant.
Please could anyone show me a way to use a group of 10 Constants in the same
way as I have used the 10 values stored in Names.

Thankyou in anticipation
--
Roger

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Constants


Jacob - thanks but......

if I had:-

Public Const Site1 as String = "Bolton"
Public Const Site2 as String = "Grimsby"
Public Const Site3 as String = "Chorley"
Public Const Site4 as String = "Wigan"
Public Const Site5 as String = "Bury"

How would I need to change the code below to make it work

Sub SetSite()
Dim Ctr as Byte
For Ctr = 1 to 4
Range("A" & Ctr) = "Site" & Ctr
Next
End Sub

Thanks for taking an intrest - Rog






--
Roger


"Roger" wrote:

I store some values in "Names"
EG Names "Site1" to "Site10" store 10 locations such as "Site1" = Bolton
"Site2" = Chorley Etc
I can retrieve them like this

Sub SetNames()
Dim Ctr as Byte
For Ctr = 1 to 10
Range("A" & Ctr) = Application.Evaluate("Site" & Ctr)
Next
End Sub

I have tried storing the values in Constants but I cannot retrieve them in
the same way as shown above. I have to write a seperate line of code for each
Constant.
Please could anyone show me a way to use a group of 10 Constants in the same
way as I have used the 10 values stored in Names.

Thankyou in anticipation
--
Roger

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Constants

You cannot.

If this post helps click Yes
---------------
Jacob Skaria


"Roger" wrote:

Jacob - thanks but......

if I had:-

Public Const Site1 as String = "Bolton"
Public Const Site2 as String = "Grimsby"
Public Const Site3 as String = "Chorley"
Public Const Site4 as String = "Wigan"
Public Const Site5 as String = "Bury"

How would I need to change the code below to make it work

Sub SetSite()
Dim Ctr as Byte
For Ctr = 1 to 4
Range("A" & Ctr) = "Site" & Ctr
Next
End Sub

Thanks for taking an intrest - Rog






--
Roger


"Roger" wrote:

I store some values in "Names"
EG Names "Site1" to "Site10" store 10 locations such as "Site1" = Bolton
"Site2" = Chorley Etc
I can retrieve them like this

Sub SetNames()
Dim Ctr as Byte
For Ctr = 1 to 10
Range("A" & Ctr) = Application.Evaluate("Site" & Ctr)
Next
End Sub

I have tried storing the values in Constants but I cannot retrieve them in
the same way as shown above. I have to write a seperate line of code for each
Constant.
Please could anyone show me a way to use a group of 10 Constants in the same
way as I have used the 10 values stored in Names.

Thankyou in anticipation
--
Roger



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Constants


Function GetSite(i as Integer)
Const SITES as string = "Bolton|Grimsby|Chorely|Wigan|Bury"
GetSite = Split(SITES,"|")(i-1)
End Function

Sub SetSite()
Dim Ctr as Integer
For Ctr = 1 to 4
Range("A" & Ctr).Value = GetSite(Ctr)
Next
End Sub

Tim

"Roger" wrote in message
...
Jacob - thanks but......

if I had:-

Public Const Site1 as String = "Bolton"
Public Const Site2 as String = "Grimsby"
Public Const Site3 as String = "Chorley"
Public Const Site4 as String = "Wigan"
Public Const Site5 as String = "Bury"

How would I need to change the code below to make it work


Thanks for taking an intrest - Rog






--
Roger


"Roger" wrote:

I store some values in "Names"
EG Names "Site1" to "Site10" store 10 locations such as "Site1" = Bolton
"Site2" = Chorley Etc
I can retrieve them like this

Sub SetNames()
Dim Ctr as Byte
For Ctr = 1 to 10
Range("A" & Ctr) = Application.Evaluate("Site" & Ctr)
Next
End Sub

I have tried storing the values in Constants but I cannot retrieve them
in
the same way as shown above. I have to write a seperate line of code for
each
Constant.
Please could anyone show me a way to use a group of 10 Constants in the
same
way as I have used the 10 values stored in Names.

Thankyou in anticipation
--
Roger



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Constants


the only things I could think of were the same as Jacob's answer.
Reality is that this is Excel .... and if you have a table of names, then
put in into a spreadsheet. It becomes far more manageable, maintainable and
scalable.

Sub SetNames()
Dim cell as Range
dim index as long
For Each cell in Range("MySiteTable").Cells
index = index +1
Range("A" & index) = cell.Value
Next
End Sub



"Roger" wrote in message
...
I store some values in "Names"
EG Names "Site1" to "Site10" store 10 locations such as "Site1" = Bolton
"Site2" = Chorley Etc
I can retrieve them like this

Sub SetNames()
Dim Ctr as Byte
For Ctr = 1 to 10
Range("A" & Ctr) = Application.Evaluate("Site" & Ctr)
Next
End Sub

I have tried storing the values in Constants but I cannot retrieve them in
the same way as shown above. I have to write a seperate line of code for
each
Constant.
Please could anyone show me a way to use a group of 10 Constants in the
same
way as I have used the 10 values stored in Names.

Thankyou in anticipation
--
Roger


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
xl constants Brettjg Excel Programming 4 April 6th 09 12:56 PM
not sure on constants Curt Excel Programming 3 April 10th 07 07:04 PM
constants Confused Excel Discussion (Misc queries) 3 December 2nd 04 05:05 PM
constants alekm Excel Programming 1 September 9th 04 12:16 PM


All times are GMT +1. The time now is 11:35 AM.

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

About Us

"It's about Microsoft Excel"