Minggu, 02 Oktober 2011

[ExcelVBA] Re: Indirect Variables

 

OK, so I didn't assign values to the variables as the OP stated, so instead, is this cheating?:

Sub blah()
Dim val As New Collection
Val1 = "apple"
val2 = "banana"
Val3 = "carrot"

val.Add Val1, "val1"
val.Add val2, "val2"
val.Add val2, "val3"
TestVar = "Val2"
MsgBox val(TestVar)
End Sub

--- In ExcelVBA@yahoogroups.com, "A.J. Morales" <ajmorales@...> wrote:
>
> put a 'stop' statement after the variable assignment:
>
> TestVar = "Val2"
> stop
>
>
>
> the code will stop after the 'stop' statement.
> Open up the 'Locals' window on the VBA side & you can see the resulting variable assignment.
>
> AJ
>
>
> ________________________________
> From: Pascal <pascaldaulton@...>
> To: ExcelVBA@yahoogroups.com
> Sent: Friday, September 30, 2011 6:15 PM
> Subject: [ExcelVBA] Re: Indirect Variables
>
>
>  
> Is this cheating?:
>
> Sub blah()
> Dim val As New Collection
> val.Add "apple", "val1"
> val.Add "banana", "val2"
> val.Add "carrot", "val3"
> TestVar = "Val2"
> MsgBox val(TestVar)
> End Sub
>
> --- In ExcelVBA@yahoogroups.com, "paulschreinerindy" <schreiner_paul@> wrote:
> >
> > I have a co-worker that has come to me with a question.
> > I'm pretty sure I've done this in the past, but
> > I cannot seem to locate it in my 80,000 lines of VBA code!
> >
> > We have several variables:
> > Val1 = "apple"
> > Val2 = "banana"
> > Val3 = "carrot"
> >
> > there is another variable that will result in
> > having the value of one of these variable NAMES.
> >
> > TestVar = "Val2"
> >
> > How do we determine the value of the variable
> > represented by the value of TestVar?
> >
> > That is: msgbox val(TestVar)
> > displays: "banana"
> >
> > (similar to the INDIRECT() function in Excel, but for variables)
> >
> > Paul
> >
>
>
>
>
> [Non-text portions of this message have been removed]
>

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar