Search notes:

Office Object Model: Excel - Application / set operations

The application object provides the two functions union and intersect with which «set operations» can be performed with ranges.

union

option explicit

public sub main()

    dim range_1      as range
    dim range_2      as range

    dim range_result as range

    set range_1 = activeSheet.range("d3:f9")
    set range_2 = activeSheet.range("b6:h7")

    set range_result = union (range_1, range_2)

    range_result.interior.color = RGB(255, 127 , 30)

    activeWorkbook.saved = true

end sub
Github repository about-MS-Office-object-model, path: /Excel/Application/union.bas
See also the union operator in formulas.

intersect

option explicit

public sub main()

    dim range_1      as range
    dim range_2      as range

    dim range_result as range

    set range_1      = activeSheet.range("d3:f9")
    set range_2      = activeSheet.range("b6:h7")
    set range_result = intersect (range_1, range_2)

    range_1.value="Range 1"
    range_2.value="Range 2"

    range_result.value="Intersection"

    activeWorkbook.saved = true

end sub
Github repository about-MS-Office-object-model, path: /Excel/Application/intersect.bas
See also the intersect operator in formulas.

TODO

application.range seems to correspond to the colon operator.

Index