Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"?B?QWk=?=" wrote...
It seems that if the range 1 and range2 in Intersect (Range range1, Range ranges2 , ...) are in different worksheets this method throws HRESULT: 0x800A03EC exception. I am using c#. C# provides syntax for exception handling through try..catch..finally blocks. It may prove more efficient to trap the exceptions than to compare objects' parents' and grandparents' names. Note that C# also has an 'is' operator, but it functions like VBA's 'TypeOf x Is y', not like VBA's plain 'Is' operator. It's unclear to me (maybe just because I don't have an MSDN subscription or a lot of VB[A] books) whether VBA's 'Is' operator is a reference or value equality operator. In C terms, whether it's checking that pointers are pointing to the same piece of memory or whether what they're pointing to is the same. Going the opposite direction that Tushar and Tom went in discussing Is vs .Name, as long as your range objects aren't NULL/Nothing (easily checked), you can safely access their Address properties. You can compare Address(,,, 1) results from all range objects up to the rightmost exclamation point in each(since exclamation points may appear in workbook directory and filenames, but not in range addresses). If they're the same, then you can use Intersect (and Union) without throwing an exception. With regard to string comparisons using Name properties, don't use Name properties to check for the same worksheets. Use Index properties and integer comparisons instead. For workbooks, since there's a possibility multiple Excel application instances could be involved, don't use Name properties to check for the same workbooks. Use FullName properties to make absolutely sure that you're not working with ranges from workbooks with the same base filename but stored in different directories. -- To top-post is human, to bottom-post and snip is sublime. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Uisng the Max and Index function to link to other workbooks | Excel Discussion (Misc queries) | |||
Uisng an option group query | New Users to Excel | |||
calculating a weighted average uisng formula | Excel Worksheet Functions | |||
Access a internet Web Site uisng a macro done with excel | Excel Programming | |||
Is there a "Non-Intersect" VBA method to remove a sub-range from a range? | Excel Programming |