Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Named ranges on other sheets

Hello all,

I have given cells A1070:B1070 on sheets 2, 3, 4 unique names (6 names, 2 cells on each sheet). In my code I can use
"Range([RangeName])" to refer to the cells on the active sheet only. In order to refer to named ranges on other sheets I need to
use "Worksheets([SheetName]).Range([RangeName])".

Does anyone know why this is so? If each cell on the 3 different sheets has a unique name, why do I need to tell it which sheet to
look at? Is there any way arond this (other than declaring 6 range object variables and setting them = to each named range)?

--
Thanks for any help anyone can provide,

Conan Kelly


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Named ranges on other sheets

What exactly are you trying to accomplish? Can you paste the code that
you have dealing with the named range?

Charles

Conan Kelly wrote:
Hello all,

I have given cells A1070:B1070 on sheets 2, 3, 4 unique names (6 names, 2 cells on each sheet). In my code I can use
"Range([RangeName])" to refer to the cells on the active sheet only. In order to refer to named ranges on other sheets I need to
use "Worksheets([SheetName]).Range([RangeName])".

Does anyone know why this is so? If each cell on the 3 different sheets has a unique name, why do I need to tell it which sheet to
look at? Is there any way arond this (other than declaring 6 range object variables and setting them = to each named range)?

--
Thanks for any help anyone can provide,

Conan Kelly


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Named ranges on other sheets

I find:

dim myRng as range
set myrng = worksheets("sheet999").range("somerangename")

more useful (more self documenting??) to use than:

dim myRng as range
set myrng = activeworkbook.names("somerangename").referstorang e

===
But ranges belong to worksheets. Either you explicitly specify the worksheet
that contains that range or you rely on the excel's treatment of unqualified
ranges (unqualified ranges will belong to the activesheet -- if the code is in a
General module).


You could also rely on what the activeworkbook is and use something like:

MsgBox Application.Range("test1").Address(external:=True)
MsgBox Application.Range("test2").Address(external:=True)

But I think the more you qualify stuff, the better:

dim myRng as range
dim wkbk as workbook
set wkbk = workbooks("somebook.xls")
set myrng = wkbk.worksheets("sheet999").range("somerangename")

Is about as safe as I get.



Conan Kelly wrote:

Hello all,

I have given cells A1070:B1070 on sheets 2, 3, 4 unique names (6 names, 2 cells on each sheet). In my code I can use
"Range([RangeName])" to refer to the cells on the active sheet only. In order to refer to named ranges on other sheets I need to
use "Worksheets([SheetName]).Range([RangeName])".

Does anyone know why this is so? If each cell on the 3 different sheets has a unique name, why do I need to tell it which sheet to
look at? Is there any way arond this (other than declaring 6 range object variables and setting them = to each named range)?

--
Thanks for any help anyone can provide,

Conan Kelly


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Named ranges on other sheets

Go with Dave's excellent advice but I expect the reason for the scenario you
describe is because you are using worksheet level (local) names and not
workbook level (global).

Regards,
Peter T

"Conan Kelly" <CTBarbarin at msn dot com wrote in message
...
Hello all,

I have given cells A1070:B1070 on sheets 2, 3, 4 unique names (6 names, 2

cells on each sheet). In my code I can use
"Range([RangeName])" to refer to the cells on the active sheet only. In

order to refer to named ranges on other sheets I need to
use "Worksheets([SheetName]).Range([RangeName])".

Does anyone know why this is so? If each cell on the 3 different sheets

has a unique name, why do I need to tell it which sheet to
look at? Is there any way arond this (other than declaring 6 range object

variables and setting them = to each named range)?

--
Thanks for any help anyone can provide,

Conan Kelly




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink to named ranges and sheets in Excel not working in 2007 Andy Boruta Excel Discussion (Misc queries) 0 December 17th 09 08:53 PM
Copy data in named ranges to a newer version of the same template to identical ranges handstand Excel Programming 0 August 21st 06 03:51 PM
copy all named ranges in a sheet to seperate sheets Chris Salcedo Excel Programming 8 October 10th 05 06:23 AM
named ranges and copying sheets to another workbook helpwithXL Excel Programming 1 May 17th 05 04:57 PM
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"