PC Review


Reply
Thread Tools Rate Thread

How to access VBA variable from active worksheet

 
 
Andrew
Guest
Posts: n/a
 
      23rd May 2009
Hello,
I have a VBA program which contains about 100 variables. I would like
to be able to see the value of any of those variables from the
worksheet. On the worksheet I have created a drop down list with all
of my possible variable names, and my VBA code looks at the value of
this list to determine which variable it should spit out to the
worksheet. The problem is that when the VBA code reads the list
value, the value comes in as a string, and even through the string
matches the variable name, the VBA output to the worksheet is not the
variable value, but the literal string value.

For example

Dim X as double
Dim Y as double
Dim select as string
select =cells(1,1) ' Cells(1,1) contains "X"

For K=1 TO 10
Y=2*X
cells(1,2)=select ' Ideally, this would spit out the value of X.
But it returns "X" as a string
Next

So, how do I declare "select" so that it enters the VBA code as a call
to the variable?

thanks

 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      23rd May 2009
the only way i can think of would be to have a list of variables in code
too. pretty redious


Function VariableValue(sVariableName as stricng)
select case sVariableName
case "X" : VariableValue=X
case "Y" : VariableValue=Y
case "Other" : VariableValue=Other
End Select
End Function

sub GetValues()
cells(1,2) = VariableValue( cells(1,1) )
End Sub

"Andrew" <(E-Mail Removed)> wrote in message
news:04820622-7e1b-4eed-8cfd-(E-Mail Removed)...
> Hello,
> I have a VBA program which contains about 100 variables. I would like
> to be able to see the value of any of those variables from the
> worksheet. On the worksheet I have created a drop down list with all
> of my possible variable names, and my VBA code looks at the value of
> this list to determine which variable it should spit out to the
> worksheet. The problem is that when the VBA code reads the list
> value, the value comes in as a string, and even through the string
> matches the variable name, the VBA output to the worksheet is not the
> variable value, but the literal string value.
>
> For example
>
> Dim X as double
> Dim Y as double
> Dim select as string
> select =cells(1,1) ' Cells(1,1) contains "X"
>
> For K=1 TO 10
> Y=2*X
> cells(1,2)=select ' Ideally, this would spit out the value of X.
> But it returns "X" as a string
> Next
>
> So, how do I declare "select" so that it enters the VBA code as a call
> to the variable?
>
> thanks
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access a Variable from the Worksheet Gary''s Student Microsoft Excel Programming 2 14th Aug 2008 12:30 PM
Access a VBA global variable/constant from a worksheet cell Lina Microsoft Excel Programming 1 29th Jul 2008 07:46 PM
Looking up a variable in one worksheet and copying information from another column to another worksheet?? Brad Torken Microsoft Excel Misc 2 10th Dec 2006 06:02 AM
Basic Question - How do I return the worksheet number of the active worksheet? Regnab Microsoft Excel Programming 2 17th May 2006 03:02 AM
Naming a worksheet as a variable in a Active Chart Series =?Utf-8?B?RmFyb29xIFNoZXJp?= Microsoft Excel Programming 5 26th Jan 2006 08:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:42 PM.