XLA routines: EE_RangeUnion

Nick's picture
Use EE_RangeUnion to add ranges together - Takes up to 6 ranges
Function EE_RangeUnion(rng1 As range, Optional rng2 As range, Optional rng3 As range, _
    Optional rng4 As range, Optional rng5 As range, Optional rng6 As range) As range
 
'http://excelexperts.com/xla-routines-eeRangeUnion    for updates on this function

    If rng2 Is Nothing Then
        Set EE_RangeUnion = rng1
    ElseIf rng3 Is Nothing Then
        Set EE_RangeUnion = Union(rng1, rng2)
    ElseIf rng4 Is Nothing Then
        Set EE_RangeUnion = Union(rng1, rng2, rng3)
    ElseIf rng5 Is Nothing Then
        Set EE_RangeUnion = Union(rng1, rng2, rng3, rng4)
    ElseIf rng6 Is Nothing Then
        Set EE_RangeUnion = Union(rng1, rng2, rng3, rng4, rng5)
    Else
        Set EE_RangeUnion = Union(rng1, rng2, rng3, rng4, rng5, rng6)
    End If
End Function