Jumat, 30 September 2011

Re: [ExcelVBA] Indirect Variables

 

AFAIK you can't do this with VBA variables. (You can with cells and you can
with field names in forms, so that might be what you're thinking of.)

At one stage I did look at dynamic creation of code, but that was at a
module level and more trouble than it was worth, IIRC.

Your co-worker should go back and look at code design. The variables should
presumably be in an array if they are associated with each other. Failing
that, a function that returns a particular item using a case statement would
seem to be the best approach.

Regards, Dave S

----- Original Message -----
From: "paulschreinerindy" <schreiner_paul@att.net>
To: <ExcelVBA@yahoogroups.com>
Sent: Friday, September 30, 2011 9:55 PM
Subject: [ExcelVBA] Indirect Variables

>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
>
>
>
> ------------------------------------
>
> ----------------------------------
> 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
>
> ----------------------------------Yahoo! Groups Links
>
>
>
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 10.0.1410 / Virus Database: 1520/3925 - Release Date: 09/28/11
>

__._,_.___
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