Combining Text to Produce a Variable Name

V

VicWestVan

I have defined 2 variables AB01 and AB02 as follows:

Dim AB01, AB02 as Range

and mapped them to row ranges using

Set AB01 = Rows("1:100")
Set AB02 = Rows("101:200")

and wish to Select a row group depending on whether the
Application.Caller.Name is "Picture 1" or "Picture 2"... something like the
following (which is not correct but conveys what I'm trying to do):

"AB"+Right(Application.Caller.Name,2).Select

Any ideas on how to achieve the objective above.
 
G

Gary''s Student

Make a string variable and then use the RANGE() function.

Something like


Dim S1, S2, S3 as String
S1="AB"
S2="Picture 1"
Range(S1 & Right(S2,1)).Select
 
D

Die_Another_Day

Use an array for the variable
Dim AB0(1 to 2) as Range
Set AB0(1) = Rows("1:100")
Set AB0(2) = Rows("101:200")
AB0(Right(Application.Caller.Name,1)).Select

Also a side note for you, in this statement:
Dim AB01, AB02 as Range

Only AB02 is Dimmed as a Range, to dim both as ranges do this:
Dim AB01 as Range, AB02 as Range

Charles
 
V

VicWestVan

Thx.... exactly what I needed.

Die_Another_Day said:
Use an array for the variable
Dim AB0(1 to 2) as Range
Set AB0(1) = Rows("1:100")
Set AB0(2) = Rows("101:200")
AB0(Right(Application.Caller.Name,1)).Select

Also a side note for you, in this statement:
Dim AB01, AB02 as Range

Only AB02 is Dimmed as a Range, to dim both as ranges do this:
Dim AB01 as Range, AB02 as Range

Charles
 

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

Top