locked
Union - Book Excel 2016 VBA and Macros Styding RRS feed

  • Question

  • Whats wrong this code from book:

    Sub union()

    Set UnionRange = Union(Range("range1"), Range("range2"))
    With UnionRange
       .Formula = "=rand()"
       .Font.Bold = True
    End With


    End Sub

       
    Saturday, May 23, 2020 9:33 PM

All replies

  • Union is a built-in function, used in the line

    Set UnionRange = Union(Range("range1"), Range("range2"))

    The macro should not be named union - that confuses Excel. You should change the name, for example to UnionDemo:

    Sub UnionDemo()
    ...


    Regards, Hans Vogelaar (https://www.eileenslounge.com)

    Saturday, May 23, 2020 10:09 PM