Find The Intersection Of Two Ranges

I m ou can use the Intersect method to determine where multiple ranges intersect on a worksheet. A multiple area range contains more than one block of cells that may or may not be connected. You use the Intersect method to create a Range object containing the cells that are common between two ranges. For example, if you have the ranges A1 through C5 and C1 through E5, the Intersect method returns the range C1:C5 because those are the cells that are common to both ranges. If there are no cells in common between the specified ranges, the Intersect method returns an empty range.

When you use the Intersect method, you can assign any number of parameter values, as long as you specify at least two different ranges. Each parameter value must specify a range of cells. You can specify the ranges you assign to the

Intersect method using any option that returns a valid Range object, such as the Range property or the Cells property. See the sections "Using the Range Property" and "Using the Cells Property" for more information on the

Range and Cells properties.

Because you must declare the variable to which you assign the multi-area range as a Range object, you need to use the Set statement as part of the assignment statement. You must use the Set statement whenever you assign an object to a variable. See Chapter 4 for more information on assigning objects. Keep in mind, however, that when you assign an intersecting range to a range object variable, only the cells within the intersection of the range are assigned to the variable, creating a new range that represents the intersection of the original ranges.

FIND THE INTERSECTION OF TWO RANGES

FIND THE INTERSECTION OF TWO RANGES

□ Create a new subroutine.

Type Set Range1 = Range("A1:CI3"), replacing Range("A1:C13") with a reference to the first range.

0 Type Set Range2 = Range("B5:D15"), replacing Range("B5:D15") with a reference to the second range.

□ Create a new subroutine.

Type Dim Range1 As Range, replacing Range1 with the name of the first range.

< Type Dim Range2 As Range, replacing Range2 with the name of the second range.

_Q Type Dim NewRange As Range, replacing NewRange with the name of the combined range.

Type Set Range1 = Range("A1:CI3"), replacing Range("A1:C13") with a reference to the first range.

0 Type Set Range2 = Range("B5:D15"), replacing Range("B5:D15") with a reference to the second range.

0 0

Post a comment