Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dev dev is offline
external usenet poster
 
Posts: 66
Default How to get individual range objects from a set of range objects?

I set up myRange to contigious cells - now how do I get individual range
objects from it?
Ex: I set myRange = Worksheets("Sheet1").Range("B15:B17") - now I want to
get B15, B16; B17. Is there any way to get this using Excel OM?

Thanks for any suggestion!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to get individual range objects from a set of range objects?

dim myrange as range, cell as range

set myRange = Worksheets("Sheet1").Range("B15:B17")
for each cell in MyRange
msgbox cell.Address
Next

'to refer to the 2nd cell in the range
msgbox myRange(2)

--
Regards,
Tom Ogilvy


"Dev" wrote:

I set up myRange to contigious cells - now how do I get individual range
objects from it?
Ex: I set myRange = Worksheets("Sheet1").Range("B15:B17") - now I want to
get B15, B16; B17. Is there any way to get this using Excel OM?

Thanks for any suggestion!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How to get individual range objects from a set of range objects?


Dim myRange as Range, cell as Range
myRange = Worksheets("Sheet1").Range("B15:B17")

for each cell in myRange
msgbox cell.Address
Next

for i = 1 to myrange.count
msgbox myrange(i).Address
Next

--
Regards,
Tom Ogilvy



"Dev" wrote:

I set up myRange to contigious cells - now how do I get individual range
objects from it?
Ex: I set myRange = Worksheets("Sheet1").Range("B15:B17") - now I want to
get B15, B16; B17. Is there any way to get this using Excel OM?

Thanks for any suggestion!



  #4   Report Post  
Posted to microsoft.public.excel.programming
dev dev is offline
external usenet poster
 
Posts: 66
Default How to get individual range objects from a set of range object

I tried the same thing from C# - I am getting "Member not found" exception.

foreach (Excel1.Range range in r)
{
string cellAddress = ((Excel1.Range)range.Cells).get_Address
(Type.Missing, Type.Missing, Excel1.XlReferenceStyle.xlA1,Type.Missing,
Type.Missing);
h.Add(cellAddress);
}

"Tom Ogilvy" wrote:

dim myrange as range, cell as range

set myRange = Worksheets("Sheet1").Range("B15:B17")
for each cell in MyRange
msgbox cell.Address
Next

'to refer to the 2nd cell in the range
msgbox myRange(2)

--
Regards,
Tom Ogilvy


"Dev" wrote:

I set up myRange to contigious cells - now how do I get individual range
objects from it?
Ex: I set myRange = Worksheets("Sheet1").Range("B15:B17") - now I want to
get B15, B16; B17. Is there any way to get this using Excel OM?

Thanks for any suggestion!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 200
Default How to get individual range objects from a set of range objects?

Dev wrote:
I set up myRange to contigious cells - now how do I get individual range
objects from it?
Ex: I set myRange = Worksheets("Sheet1").Range("B15:B17") - now I want to
get B15, B16; B17. Is there any way to get this using Excel OM?

Thanks for any suggestion!



To expand on Tom Ogilvy's response, you can refer to any single cell in
a contiguous range of cells with single indexing or double indexing.
Considering first a multi-row, multi-column range, myRange(1) will refer
to the upper leftmost cell; myRange(2) will refer to the next cell to
the right and so on until the rightmost column has been referred to,
then to the leftmost column in the second row. The contiguous range that
is accessible this way extends in fact to the bottom of the worksheet.
E.g., considering the range C4:E6, the references will be as follows:

myRange(1)-C4
myRange(2)-D4
myRange(3)-E4
myRange(4)-C5
myRange(5)-D5
myRange(6)-E5
myRange(7)-C6
myRange(8)-D6
myRange(9)-E6
myRange(10)-C7
myRange(11)-D7
myRange(12)-E7 and so on down to
myRange(196597)-C65536
myRange(196598)-D65536
myRange(196599)-E65536

It follows that if the range is a single row, e.g., C4:E4, the
references will be to the same cells as for C4:E6 (because the counting
goes left to right then down and back to the left and so on); and if the
range is a single column, e.g., C4:C6, the references will be

myRange(1)-C4
myRange(2)-C5
myRange(3)-C6
myRange(4)-C7 and so on down to
myRange(65533)-C65536

You can also refer to any cell in a contiguous range with 2 index
numbers as with a VBA array, and again the accessible range continues on
down the worksheet. E.g., again considering myRange=C4:E6

myRange(1,1) refers to C4
myRange(1,2) to D4
myRange(1,3) to E4
myRange(2,1) to C5
myRange(2,2) to D5
myRange(2,3) to E5
myRange(3,1) to C6
myRange(3,2) to D6
myRange(3,3) to E6
myRange(4,1) to C7
myRange(4,2) to D7
myRange(4,3) to E7 and so on down the sheet

The cells of a single row could be referred to the same way, and to a
single column, e.g., C4:C6,

myRange(1,1)-C4
myRange(2,1)-C5
myRange(3,1)-C6
myRange(4,1)-C7 and so on down the sheet.

Alan Beban


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
How do range objects work? Ken McLennan[_3_] Excel Programming 4 May 20th 06 10:39 AM
Cut Drawing Objects within a range CLR Excel Programming 1 January 20th 06 05:31 PM
Range objects in a collection Corey B Excel Programming 2 September 25th 04 06:24 PM
Range objects (?) Bill[_19_] Excel Programming 1 December 23rd 03 02:37 PM
Cannot use range objects jason Excel Programming 7 November 27th 03 03:00 AM


All times are GMT +1. The time now is 10:55 AM.

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

About Us

"It's about Microsoft Excel"