Is there a union operator in Excel?
Excel's 'union' operator has always been the comma* (e.g. A1:A9,F2:G4
) while its intersect operator is a single space. It's not that it doesn't work, it's just that not all Excel functions can accept this reference method.
Here are some that do:
SUM()
COUNT()
COUNTA()
SMALL()
LARGE()
MIN()
MAX()
AVERAGE()
However, when you think about it, the ,
does not exactly do mathematical union, but rather set addition. For example, =COUNT(A1,A1,A1)
returns 3
. If it were truly a union operator, this formula would return 1
.
**Some Euro-versions use the semicolon (;
) instead, depending on the computer's regional settings.*
(Further reading: Microsoft Office: Calculation operators and precedence)
If you want to sum values, you can write this:
=SUM(I3:M3;I4:M4;I5:M5)
If you want to merge texts, you can write this (or use your mouse as @soandos says):
=CONCATENATE(A1;B1;C1;D1)
It looks like you want to write . But, as I know, it is not possible (gives error).=CONCATENATE(A1:D1)
The question is not too clear, but for now, it seems like you have to merge texts. So for instance – as per your example if you have to union E2, E3, E4, E5, E6 you can write a formula like:
=CONCATENATE(E2,E3,E4,E5,E6)
I tried it myself: You have to individually describe cells. ":" This is not working for me too in Concatenate. So you should try as explained above.
Else, mmdemirbas's answer perfectly explains the SUM
formula.
In short the answer is NO.
However, for some functions you can use the following workaround,
=COUNTA(B1:B3,A2:C2)-COUNTA(B1:B3 A2:C2)
Note that the ranges have one cell in common (ie intersecting). The "," is used by some functions to allow multiple range to be provided as parameter. This is not a union as this will include the intersection cell twice. It will be COUNTED TWICE. So, by subtracting the intersection you get the correct answer.
This technique should work with the following:
SUM()
COUNT()
COUNTA()
It won't work with:
SMALL()
LARGE()
The formula can be modified to work with:
AVERAGE()
It is never required with MAX and MIN
!
It's a real pain that it works like this and that there is no UNION operator.
In VBA you can write a function that create a proper union:
see here for info http://www.cpearson.com/excel/BetterUnion.aspx
ie
Function ProperUnion(ParamArray Ranges() As Variant) As Range
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ProperUnion
' This provides Union functionality without duplicating
' cells when ranges overlap. Requires the Union2 function.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ResR As Range
Dim N As Long
Dim R As Range
If Not Ranges(LBound(Ranges)) Is Nothing Then
Set ResR = Ranges(LBound(Ranges))
End If
For N = LBound(Ranges) + 1 To UBound(Ranges)
If Not Ranges(N) Is Nothing Then
For Each R In Ranges(N).Cells
If Application.Intersect(ResR, R) Is Nothing Then
Set ResR = Union2(ResR, R)
End If
Next R
End If
Next N
Set ProperUnion = ResR
End Function