RectIntersect Method

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Returns a Range object that represents the rectangular intersection of the specified ranges. Returns Nothing if the specified ranges do not overlap.

expression.RectIntersect(Range1, Range2)

expression   Required. An expression that returns a Spreadsheet object

Range1  Required Range.

Range2  Required Range.

Example

This example bolds the cells where the named range "Range1" overlaps the named range "Range2" in the active sheet of Spreadsheet1.

  Sub BoldIntersection()

    Dim rngIntersect
    Dim rngFirstRange
    Dim rngSecondRange

    ' Set a variable to the first named range.
    Set rngFirstRange = Spreadsheet1.ActiveSheet.Range("Range1")

    ' Set a variable to the second named range.
    Set rngSecondRange = Spreadsheet1.ActiveSheet.Range("Range2")

    ' Set a variable to the intersection of the two named ranges.
    Set rngIntersect = Spreadsheet1.RectIntersect(rngFirstRange, rngSecondRange)

    ' Check whether the named ranges overlap.
    If Not rngIntersect Is Nothing Then

        ' Bold the font in the overlapping portion
        ' of the two ranges.
        rngIntersect.Font.Bold = True

    End If

End Sub