Excel: Selecting Intersection of Two Ranges with a Macro

Last reviewed: July 24, 1995
Article ID: Q57196

SUMMARY

In Microsoft Excel, you can indicate an intersection of two ranges by separating the ranges with a single space. For example:

      The Reference               Returns the Range
      -------------               -----------------

      $A$1:$B$10 $B$3:$D$12       $B$3:$B$10
      $A:$C $1:!10                $A$1:$C$10
      Name1 Name2                 intersection of two named ranges


As an example, the following SELECT statement can be used in a macro to select the intersection of two named ranges

   =SELECT(!NAME1 !NAME2)

where NAME1 and NAME2 are defined names referring to ranges on a worksheet or macro sheet.

The blank space between the defined names instructs Excel to find the intersection of the two ranges.

Note: If the ranges never intersect (that is, they're parallel), the reference will return #NULL! and the SELECT statement will cause a macro error, halting the macro.

For information about how to do this in Microsoft Excel 5.0, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120198
   TITLE     : XL5: How to Select Cells/Ranges Using Visual Basic
               Procedures


KBCategory: kbother
KBSubcategory:

Additional reference words: 1.00 1.03 1.04 1.06 1.50 2.20 3.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 24, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.