Check Cells for Equality – Follow Up [Quick Tip]

Last week in Write a formula to check few cells have same value [Homework],

Chandoo posed the question: Can you write a formula to check if a few cells are equal?

 

A lot of people answered with answers like:

=IF(COUNTIF(A1:A4,A1)=COUNT(A1:A4),TRUE,FALSE)

or

=IF(SUM(A1:A4)/COUNT(A1:A4)=A1,TRUE,FALSE)

or

=IF(PRODUCT($A:$A)=A1^(COUNTIF($A:$A,A1)),”Yes”,”No”)

etc.

Although these are all correct, the formulas can be simplified by using a built in function of Excel

The function is

 

=

In Excel the = sign does two things

1. When the = sign is the first character of a Cell, Named Formula or Reference it tells the Cell, Named Formula or Reference that it contains a formula

2. It acts as an equality function when it has a value or formula on either side of it

 

What does the = function do?

What does the = function do?

The = function returns a Boolean or TRUE / FALSE value depending on the equality of the values/formula on either side of it

Example:

In a blank cell enter =2=1

Excel will display FALSE to tell us that the values aren’t equal

Now change the formula to =2=2

Excel will display TRUE to tell us that the values are equal

 

Either side of the = sign can contain a Formula, Cell Reference etc

=(200/100)=2 will return TRUE

=SIN(PI()/2)=1 will return TRUE

=SIN(PI()/2)=15 will return FALSE

=-1=COS(PI()) will Return TRUE

 

=SIN(PI()/2)=A1 will return TRUE if cell A1 contains either a 1 or a formula that returns the value 1.

It will return False for all other values.

 

So the above, Homework, formulas can be simplified as :

Original: =IF(COUNTIF(A1:A4,A1)=COUNT(A1:A4),TRUE,FALSE)

Simplified=COUNTIF(A1:A4,A1)=COUNT(A1:A4)

or

Original: =IF(SUM(A1:A4)/COUNT(A1:A4)=A1,TRUE,FALSE)

Simplified: =SUM(A1:A4)/COUNT(A1:A4)=A1

or

Original: =IF(PRODUCT($A:$A)=A1^(COUNTIF($A:$A,A1)),”Yes”,”No”)

Simplified: =PRODUCT($A:$A)=A1^(COUNTIF($A:$A,A1))

and all will still, correctly, answer the question

 

Challenge:

If your formula started with an If(), see if you can rewrite it based on the above.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

19 Responses

  1. Why not something even more simple?
    =AND(G2:G5=H2:H5)
    Ctrl+Shift+Enter

    If you insist on the “If..”, then

    =If (And(G2:G5=H2:H5),”True”,False”)
    Ctrl+Shift+Enter

  2. Please ignore above…I misread the question

    Please use the below

    ={If (And(G2:G5=G2),”True”,False”)}
    Ctrl+Shift+ Enter

    Or

    ={AND(G2:G5=G2)}
    Ctrl+Shift+Enter

  3. Went back and saw that the formula I suggested is very similar to the obvious answer…so here is another

    =IF(COUNTA(I4:I7)>SUMPRODUCT(–(I4:I7=I4)),”False”,”True”)

  4. Dan u good ! Learned a new thing today.

    Here’s my new formula

    Old Formula: {=IF(SUM(IF(A1=$A:$A,1,0))=COUNTA($A:$A),TRUE,FALSE)}

    New Formula: {=SUM(IF(A1=$A:$A,1,0))=COUNTA($A:$A)}

  5. your formula with the equal sign to check ceels for equality works correctly with numbers but not with letters.

    1. Should you want to compare cellular equality with letters or text, use the =EXACT(D4,D) The result will be either TRUE or FALSE.

      MC

  6. My solution is: COUNTDIFF(A1:A4,1,)=1
    Excel function COUNTDIFF counts the number of unique values in a range or an array.
    SYNTAX :
    =COUNTDIFF(Array,Blanks,Exclude)
    Array (range or array) : can contain any type of data (numbers, text, empty cells…).
    Blanks (boolean, optional) : specifies if empty cells must be taken into account (default : FALSE).
    Exclude (value, range or array, optional) : value(s) which must be excluded from the count.
    Unlike many posted solutions, this function allows handling blank cells.
     

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.