Dynamic variable Reference

  • Thread starter Thread starter RNM
  • Start date Start date
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
 
RangeName = "ABC" & Format$(n)

where n contains the number the user entered.
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top