Dynamic variable Reference

R

RNM

In VBA, how does one make a reference to a dynamic veraiable?

If I have named ranges "ABC1" thru "ABC9".
User enters "5" so I want to get the value of range "ABC5".
Without using Case statements.

Thanks
 
M

Myrna Larson

RangeName = "ABC" & Format$(n)

where n contains the number the user entered.
 
R

RNM

How about if I need to reference a variable, not a range.

user enters a number(1-9).
I need to put a value in variable either "a1", "a2",... or "a9"
without using case statement

Thank you
 
A

Amedee Van Gasse

RNM said:
How about if I need to reference a variable, not a range.

user enters a number(1-9).
I need to put a value in variable either "a1", "a2",... or "a9"
without using case statement

Thank you,

Use an array.

Dim a(1 To 9) As Integer ' Or whatever other variable type
This single statement gives you 9 variables: a(1), a(2), a(3), ...
until a(9).

And then you use a(n) where n is the number the user entered.

--
Amedee Van Gasse using XanaNews 1.16.3.1
If it has an "X" in the name, it must be Linux?
Please don't thank me in advance. Thank me afterwards if it works or
hit me in the face if it doesn't. ;-)

I found 2 small shortcomings on www.excelforum.com:
1. You do *not* have to pay for access to 2. A *real* newsreader (not Outlook Express) is actually very easy to
use. See www.newsreaders.com for more info.
 
Top