22

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
  • A1 = B1 = C1 = D1 = E1 and so on... This will result a TRUE if all matches or a FALSE. (change range as required)
    – Vasim
    Jul 31, 2015 at 12:25
  • 4
    @Vasim - you cannot use several = signs like this. =A1=B1=C1 would yield FALSE even if values in those cells were equal.
    – ZygD
    Jul 31, 2015 at 15:55
  • why it's about formula? Feb 21 at 16:22

3 Answers 3

33

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:

  1. Select the cells you want to color
  2. Format > Conditional Formatting
  3. Select "Custom formula is"
  4. Fill in one of the above formulas without the IF part of formula, e.g.
    =AND(ARRAYFORMULA(A1={B2,C3,D4,E5,F6}))
  5. Select the formatting style (color)
  6. Done
3
  • for me, this didn't work, A1={B2,C3,D4,E5,F6} gives syntax error, but A1={B2;C3;D4;E5;F6} doesn't
    – YakovL
    Sep 14, 2021 at 11:11
  • @YakovL - it must be your locale. All basic formulas for you will require ; instead of , which does not invalidate the answer.
    – ZygD
    Sep 14, 2021 at 12:48
  • oh my, formula syntax depends on locale.. Thanks anyway!
    – YakovL
    Sep 14, 2021 at 13:55
16

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(...)

1
  • This is the best answer if you have blank cells in your range that you don't want to count as "Not Equal".
    – mang
    Jun 30, 2018 at 1:12
1

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")
1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.