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...
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...
Re: [ExcelVBA] Indirect Variables
Not quite... it still requires the array index. I haven't looked at his code, but from what he said, he's got a large number of variables. Somehow, he is retrieving a subset of the list of variables and populating a userform. (so they're no in a predictable order) The user selects one of the variables from the form, and he retrieves the value of the variable. So, what he's doing is something like Eval(variable) but, Eval expects the (variable) to resove into a function name and Eval basically calls the function. What he's REALLY wanting to do is something line Excel's Indirect() function. Only with variables instead of cells. Paul -----------------------------------------...
[belajar-excel] Digest Number 1343
Milis Belajar Microsoft Excel Messages In This Digest (15 Messages) 1a. perbandiangan 2 daftar 2 kriteria-update attachment From: Jonathan Susanto 1b. Bls: [belajar-excel] perbandiangan 2 daftar 2 kriteria-update attach From: dwint ruswanto 1c. Re: perbandiangan 2 daftar 2 kriteria-update attachment From: Kid Mr. 1d. Re: perbandiangan 2 daftar 2 kriteria-update attachment From: Jonathan Susanto 1e. Re: perbandiangan 2 daftar 2 kriteria-update attachment From: Kid...
Langganan:
Postingan (Atom)