Hello Dave,
From your post, my understanding on this issue is: you wonder how to set up
an Excel.Range object with multiple cells, how to determine if an Excel
range has a single cell, and how to get its row and column. If I'm off
base, please feel free to let me know.
1. How to set up a range with multiple cells
Excel object model exposes several ways to setup a range with multiple cells
a. Using Range to specify the range in the worksheet
e.g. Excel.Range range1 = worksheet.get_Range("A1", "B2");
b. Using Application.Union to union multiple ranges
e.g. Excel.Range range2 = (Excel.Range)worksheet.Cells[3, 3];
Excel.Range union = application.Union(range1, range2, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing);
Please *note* that the union of non-adjacent ranges will creae multiple
'Areas' in the Range object. You may want to have a look at the issue:
http://msdn.microsoft.com/newsgroups/managed/default.aspx?dg=microsoft.publi
c.office.developer.vba&mid=a3c53ac4-690d-436b-b469-a60672f784ba&sloc=en-us
to have a clearer picture about the union of non-adjacent ranges.
c. Using Application.Intersect to get the intersections of multiple ranges.
e.g. Excel.Range intersection = application.Intersect(range1,
range2, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing);
2. How to determine if an Excel.Range has a single cell.
To determine if an Excel.Range has a sigle cell, we could use
range.Cells.Count property. If the property equals 1, the range is composed
of only one cell.
3. How to get the row and column of a cell.
When we get the cell object of type Excel.Range (union.Cells[1, 1]), we
could use range.Row and range.Column properties to get the information.
Please let me know if you have any other concerns, or need anything else.
Sincerely,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document:
http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.