Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I refer to a multi-sheet named range


In VBA, how can I reference a named range that is pre-defined with cells
in various sheets of a workbook?

As far as I know, the following only works for name ranges that are
restricted to a single sheet:

Set MyRange = ThisWorkbook.Sheet(iSheet).Range("myNamedRange")

But myNamedRange is already defined as something like:

Sheet1!$A$1, Sheet2!$B$4, etc.

Thanks for any advice.
-dlh


--
dlh
------------------------------------------------------------------------
dlh's Profile: http://www.excelforum.com/member.php...o&userid=26113
View this thread: http://www.excelforum.com/showthread...hreadid=474265

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default how do I refer to a multi-sheet named range

I don't think that name refers to a range. A range has a parent that holds that
range--your name doesn't have a parent.

But you could parse the string that the name refers to and pick out the cells
that way:

Option Explicit
Sub testme01()

Dim myStr As String
Dim mySplit As Variant
Dim iCtr As Long
Dim myCell As Range

myStr = ThisWorkbook.Names("test1").RefersTo
mySplit = Split(myStr, ",")

For iCtr = LBound(mySplit) To UBound(mySplit)
For Each myCell In Application.Range(mySplit(iCtr)).Cells
MsgBox myCell.Address(external:=True)
Next myCell
Next iCtr

End Sub

split was added in xl2k. If you're using xl97, this won't work--but there are
other ways to split the string.



dlh wrote:

In VBA, how can I reference a named range that is pre-defined with cells
in various sheets of a workbook?

As far as I know, the following only works for name ranges that are
restricted to a single sheet:

Set MyRange = ThisWorkbook.Sheet(iSheet).Range("myNamedRange")

But myNamedRange is already defined as something like:

Sheet1!$A$1, Sheet2!$B$4, etc.

Thanks for any advice.
-dlh

--
dlh
------------------------------------------------------------------------
dlh's Profile: http://www.excelforum.com/member.php...o&userid=26113
View this thread: http://www.excelforum.com/showthread...hreadid=474265


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do I refer to a multi-sheet named range


To make sure I'm understanding you correctly (please bear with me as my
understanding grows):

You're saying there is no way of defining a single range that contains,
for example, one cell on each page of a workbook. Instead, I have to
parse the Name string and process the various cells individually.

True?

-dlh


--
dlh
------------------------------------------------------------------------
dlh's Profile: http://www.excelforum.com/member.php...o&userid=26113
View this thread: http://www.excelforum.com/showthread...hreadid=474265

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default how do I refer to a multi-sheet named range

In article ,
dlh wrote:

To make sure I'm understanding you correctly (please bear with me as my
understanding grows):

You're saying there is no way of defining a single range that contains,
for example, one cell on each page of a workbook.


True. Ranges are child objects of worksheets. A range object only has
one parent sheet.

Instead, I have to parse the Name string and process the various
cells individually.


Possibly. If your string can be evaluated by *some* worksheet functions,
you could use the Evaluate() method instead.

Say the value of your name, say "myname" is "=Sheet1:Sheet4!$A$1"

You could then use

Debug.Print Evaluate("=SUM(myname)")

But you'd need to be very careful. For instance if "myname"s value is
instead

=Sheet1!$A$1,Sheet2!$A$1

then

Debug.Print Evaluate("=SUM(myname)")

will return an error, and

Debug.Print Evaluate("=COUNT(myname)"), Evaluate("=COUNTA(myname)")

will return the bogus values

0 1

even if both cells contain numeric values.
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
Refer to a named range indirectly tberkom Excel Worksheet Functions 1 May 13th 09 12:33 AM
Refer to Named Range on another sheet for IF function David Excel Worksheet Functions 3 August 26th 06 04:12 AM
???Refer to a specifc cell in a named range Jaylin Excel Worksheet Functions 1 February 10th 06 11:47 AM
How does one refer to the n-1 element of a named range? Charles Hewitt Excel Discussion (Misc queries) 2 November 26th 05 06:56 AM
How do you refer to a dynamic named range? Ian Staines Excel Programming 3 September 14th 03 10:48 PM


All times are GMT +1. The time now is 09:37 AM.

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"