ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combining Text to Produce a Variable Name (https://www.excelbanter.com/excel-programming/370368-combining-text-produce-variable-name.html)

VicWestVan

Combining Text to Produce a Variable Name
 
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.

Gary''s Student

Combining Text to Produce a Variable Name
 
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
--
Gary's Student


"VicWestVan" wrote:

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.


Die_Another_Day

Combining Text to Produce a Variable Name
 
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

VicWestVan wrote:
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.



VicWestVan

Combining Text to Produce a Variable Name
 
Thx.... exactly what I needed.

"Die_Another_Day" wrote:

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

VicWestVan wrote:
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.





All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com