Let's say I have 6 different cells (that are not all in a line). I want to check if the values in these cells are equal. How could I do this with a function? I'd want the function simply to display "EQUAL" or "NOT EQUAL" (or maybe change the cell background color?).
3 Answers
One option for 6 cells would be this:
=IF(AND(A1=B2,B2=C3,C3=D4,D4=E5,E5=F6),"EQUAL","NOT EQUAL")
Another option - this way you don't need to reference the same cell twice:
=IF(AND(ARRAYFORMULA(A1={B2,C3,D4,E5,F6})),"EQUAL","NOT EQUAL")
If you wanted to color some cells if values in these cells are equal, you would need to create a Conditional Formatting rule with a similar formula:
- Select the cells you want to color
- Format > Conditional Formatting
- Select "Custom formula is"
- Fill in one of the above formulas without the
IF
part of formula, e.g.
=AND(ARRAYFORMULA(A1={B2,C3,D4,E5,F6}))
- Select the formatting style (color)
- Done
as formula for conditional formatting:
=countunique({A1,B2,C3,D4,E5,F6})=1
as function it would be similar: =if([formula],"EQUAL","NOT EQUAL"):
update: the requested clarification:
- put the wanted cells in a custom array
{A1,B2,C3,D4,E5,F6}
(delimiters:,
= new column,;
= new row; for countunique either is fine) - get the unique values
countunique(...)
- if the outcome is 1 then all values are the same
update 2: original answer used =count(unique(...))
instead of the combined function =countunique(...)
-
This is the best answer if you have blank cells in your range that you don't want to count as "Not Equal".– mangJun 30, 2018 at 1:12
Here's an option without using an array that is easier to implement for large numbers of cells:
=IF(MIN(A1,B2,C3,D4,E5,F6)=MAX(A1,B2,C3,D4,E5,F6),"Equal", "Not Equal")
-
If you need to ignore #N/A:
=MINIFS(A1:F1,A1:F1,"<>#N/A")=MAXIFS(A1:F1,A1:F1,"<>#N/A")
Jun 22, 2020 at 12:19
=
signs like this.=A1=B1=C1
would yield FALSE even if values in those cells were equal.