ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Constants (https://www.excelbanter.com/excel-programming/431533-constants.html)

Roger

Constants
 
I have several constants EG:-

Public Const Site1 as String = "Bradford"
Public Const Site2 as String = "Keighley"
Public Const Site3 as String = "Sheffield"
ETC
Instead of a long "If - ElseIf" is there a way to refer to a constant using
a variable EG
The variable entering the routine is called "Ctr" short for counter-
Its value is 2
The code below obviously does not work-
Range("A1") = "Site" & Ctr
Is there a way to write the above line of code that works please!

Many thanks if you can help

jasontferrell

Constants
 
Maybe you should use an array.

Public site(3) As String
Sub setValues()
site(1) = "Bradford"
site(2) = "Keighley"
site(3) = "Sheffield"
End Sub


Range("A1") = site(Ctr)

Roger

Constants
 
Jason - thanks - nice idea - Rog


"jasontferrell" wrote:

Maybe you should use an array.

Public site(3) As String
Sub setValues()
site(1) = "Bradford"
site(2) = "Keighley"
site(3) = "Sheffield"
End Sub


Range("A1") = site(Ctr)



All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com