range problems


Posted by Ron on December 08, 2000 1:11 PM

I am having problems with getting a range command to work. I have a worksheet with 6 tabs labelled SUM, 6401,6402,6403,6404,and 6405. I have a macro that loops through each tab in arriving at a total I put into SUM.

To add the right columns in each tab, I use this command to set the range "startRange" several times in each tab:

ActiveWorkbook.Names.Add Name:="startRange", RefersToR1C1:= _
"='6405'!R58C3"

The command above creates a unique range in the worksheet '6405'.

Instead of using the name '6405' I want to use a variable name to increase the efficiency of the subroutine like this:

MasterFocusSheet = "6405"
or
MasterFocusSheet = ActiveSheet.Name

Then use the command:

ActiveWorkbook.Names.Add Name:="startRange", RefersToR1C1:= _
"='MasterFocusSheet'!R58C3"

When I do this, I get the error message:

"Method 'Range'of object '_Global' failed"


Can anyone help me get around this?

Thanks


Posted by Tim Francis-Wright on December 08, 2000 2:27 PM


[snip]

Try a small modification to the offending statement:

ActiveWorkbook.Names.Add Name:="startRange", RefersToR1C1:= _
"='" & MasterFocusSheet & "'!R58C3"

This way you concatenate the variable MasterFocusSheet
into the middle of the string that defines the name.

HTH!



Posted by Ron on December 08, 2000 4:09 PM

HTH (Tim?)

Your fix worked great. Thanks a million for the quick response.

Ron