View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mats Samson Mats Samson is offline
external usenet poster
 
Posts: 112
Default Named ranges and variables

Hello Toppers!
Sorry but I can't get it to work. Even if I follow your instruction exactly
it stops
at the Set....-line with error 1004.
Again, this is how it looks:
I have two named ranges in the sheet Docs. myRange1 for cell A16 and
myRange2 for cell M20. Conditionally, I can run Sub StartOne () procedure and
set the condition CurRange = "myRange1". If I instead run the Sub StartTwo ()
procedure the condition is set to CurRange= "myRange2". Both these two
procedures will jump to Sub Goal() and depending on the CurRange variable it
will (should) select the requested cell through a statement similar to
CurRange.Select

Can you solve it, please
Best regards
Mats

"Toppers" wrote:

Hi,

Dim CurRange as Range
Dim i as integer

i = 1 ' or i=2 ... set your condition

Set CurRange = Worksheets("Docs").Range("MyRange" & i)
CurRange.Select


HTH

"Mats Samson" wrote:

Hello,
I'd like to select a named range that can be different depending the
conditions, and
I'd like to use a variable to contain the named range but the statement
Worksheets("Docs").Range(CurRange).Select
won't accept the CurRange variable.
Let's say I have two named ranges: myRange1 ( for the range a1:b1) and
myRange2 (for the named (range) single cell a7). Depending of the conditions
I wan't to set CurRange to contain either myRange1 or myRange 2 and the
program to select the right range. (I need to use named ranges as the
position of the named ranges will change during time.)
Is there any good solution?

Best regards
Mats Samson