LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 33
Default Use a string as a Variable Name

First let me apologize for reposting this question. I didn't get any help
yesterday and am hoping a fresh set of eyes will do the trick.

I have a large number of Constants defined sequentially as such :
Public Const BM1Left As Single = 10.2
Public Const BM2Left As Single = 18.7
Public Const BM3Left As Single = 26.4
and so on...

There are enough of these that I would prefer not to use an IF statement or
a Select Case construction to access the desired const. I would be great to
be able to access the particular constant by concatenating or otherwise
"constructing" the name such as in the code below:

Sub Test(index as integer)
Dim Left As Single
Dim myString As String
myString = "BM" & index & "Left"
Left = Evaluate(myString)
End Sub

I get a "type mismatch" with the above code because myString is a string and
Left is a Single. I have searched the discussion groups for 2 days now and
tried every variation I can think of unsuccessfully. Is there a way to get
the variable Left to recognize the name of the Const represented by the
string rather than the just the string itself? I know that named ranges on a
worksheet and buttons on a user form can be evaluated in a similar manner,
but I can not figure out how to do it in this case.

Thanks for any help you can give me.

 
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
Setting a string variable as the file name [email protected] Excel Discussion (Misc queries) 1 March 28th 07 11:10 PM
Nested String Filename Variable ed9213 Excel Worksheet Functions 9 February 12th 07 02:27 AM
find a variable text string [email protected] Excel Discussion (Misc queries) 2 January 30th 07 07:20 PM
calling variable within string [email protected] Excel Worksheet Functions 8 May 4th 06 03:07 PM
Variable in string DevinC Excel Discussion (Misc queries) 5 January 26th 06 08:59 PM


All times are GMT +1. The time now is 07:28 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"