Write a formula to check few cells have same value [homework]


Share on facebook
Share on twitter
Share on linkedin

Lets test your Excel skills. Can you write a formula to check few cells are equal?

Your homework:

  • Let us say you have four values in cells A1, A2, A3, A4
  • Write a formula to check if all 4 cells have same value (ie A1=A2=A3=A4)
  • Your output can be TRUE/FALSE or 1/0 to indicate a match (or mis-match)

Bonus question 1:

How would you write a formula if your values are in range A1:An

Bonus question 2:

What formula would work well if the cells contain non-numeric values (text, logical etc.)

Obvious answer:

The easiest and obvious answer is to test if all them are equal. The formula is,


(select the above blank line to see answer)

But can you come up with some other options to test the equality?

Click here to post your answer.

Want more Excel home works, quizzes & challenges?

Share on facebook
Share on twitter
Share on 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

Excel School made me great at work.

– Brenda

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.


Sorting values in Olympic Medal Table style [Quick Tip]

It is Olympic season. Everyone I know is tracking the games and checking their country’s performance. One thing that we notice when looking at medal tally is,

A single Gold medal is worth more than any number of Silver medals. Like wise, a single Silver medal is worth more than any number of Bronze medals.

So, when you look at the ranking of countries, you see countries with single Gold medal higher up than countries with lots of Silver and Bronze medals (but no Gold).

127 Responses to “Write a formula to check few cells have same value [homework]”

  1. Arie says:


    this also works for large ranges of numerical values (but not for text)

  2. Detlef says:


    Works for numbers, text and logical values on a range from A1:An.


  3. lockdalf says:

    well if you name the range, you could use following:


  4. Chris says:

    My solution is a, perhaphs slightly complex, array formula as follows:


    Assuming there is a value (numerical, text, logic etc) in cell A1, this formula will work - and it will 'ignore' any cells that are 'blank' within the range A1:H1 (which can be extended to the required size).

    Breaking the formula down, the SUBSTITUTE(A1:H1,A1,9999) replaces all values (be it text / numerical) in the range A1:H1 that MATCH the value of cell A1 with the number 9999 (this should be changed to any number that WON'T APPEAR IN THE RANGE).

    These values are then multiplied by 1 (as SUBSTITUTE results in a text answer).

    Wrapping this in an IF(ISBLANK(A1:H1),9999,.........) formula takes care of any blank cells, setting them to this default value of 9999 also - this allows you to set the formula up once for a large range and then not have to alter as more data comes in.

    An Average is then taken of all these values - if all cells that contain values are the same, the average will come back to 9999.

    If all values are numerical but some differ, the average will differ from 9999 and will result in a FALSE answer. If some / all of the values are text and some differ from that in cell A1, the AVERAGE function will result in an Error, but in these instances the Match needs to return FALSE, hence the IFERROR function.

    Sure there's a simpler way to do this though!!

  5. George says:

    so if your data was in Column 1 and began in A1, you'd use

    This will work for strings and things, if you want it to be case sensitive (I don't), just remove the UPPER() part.
    What this does:

    tells you how many entries you're looking at over your range (so we can work with an undetermined size).
    ISNUMBER will return TRUE or FALSE depending on if the value inside is a number or not.  the -- part converts TRUE/FALSE in to 1 or 0.
    converts the value in to upper case.  If passed a number it changes it to text format.  This is what stops it from being case sensitive.
    will return a number if A1 is contained in each cell containing an entry in column 1.
    checks that all elements are the same length.  This is needed to avoid partial matches (without it, if A1 contained zzz and A2 contained azzza it would flag as true).

    REMEMBER this is an array formula, so enter with ctrl+shift+enter.

  6. Udit says:


    Gives 0 if false and 1 if true

  7. Ray Blake says:

    =COUNTIF(A:A,A1)/COUNTA(A:A) = 1

    This meets both bonus requirements and is dynamic. Keep adding more contents in column A and it will include these automatically. 

    • Mike K says:

      I like this a one a lot. I would make one small change by inserting a table for my data range. Makes it dynamic without selecting the whole column


  8. Sudhir Gawade says:

    For only Numeric values


  9. Sandy Siegel says:


  10. Elias says:

    Case sensitive.



  11. PPH says:

    I'd use this


    It takes Hui's formula but ensures that the test value for the countif is the value or string that is most common in the range. Just in case you get a false but the problem is just with your test value being the odd one out.

  12. José Lôbo says:

    SE = IF
    E = AND

  13. Stan Cullerne-Bown says:

    Bonus question 1 & 2
    Array formula: {AND(A1=A1:AN)}
    This will test all cells in range, including text and numbers. 


  14. D Stinson says:

    A very simple solution uses Excel's Rank function.  Insert in B1 = Rank(A1, $A$1:$A$4).  Copy down this formula to B4.  If the answers in B1 thru B4 are all 1, the values are equal.  For an open range of cells, label the range of input (example "TestData") and place the label in the funtion (= Rank(A1, TestData) then copy down to an equivelent length of rows as the range.

  15. Tom Moedl says:


  16. Melanie says:


  17. Tom Moedl says:

    I enjoy your emails.  I have learned a lot from them.  Thank you for what you do.

  18. .
    Change A4 to An.

  19. jimmy says:


  20. Kishore Kumar says:

    I would use the formula which is mentioned below:-


  21. Karl says:

    At last a homework assignment that I could answer on my own. And I even understand some of the elegant answers from other readers this time.
    My solution was to nest IF statements:
    This satisfies bonus question 2 but I think the structure makes it impossible to modify this solution to satisfy bonus question 1. And I wouldn't want to use this strategy to compare very many values...

  22. Bob Bonner says:

    This answers all of your questions:


    where column A contains the values and $B$1 has the number of rows to assign to last A-cell. 

  23. Sanjay says:

    =SUM(HELLO, A1)

  24. Livigs says:

    This will work for numbers or text, and will work for any number of cells (A4 would just be An)

  25. Brian LaGrand says:

    Here's another alternate, assuming values in cells a1:d1

  26. Supertaitai says:


  27. Virginia says:


  28. Sanjay says:



  29. Don says:


  30. Bryan says:

    I would use something like this:  =COUNTA(A1:A4)=COUNTIF(A1:A4,A1)

    • Bryan says:

      You can even do a whole range and as you enter data into the range it tells you if they all match.  Going down to row 5000:  =COUNTA(A1:A5000)=COUNTIF(A1:A5000,A1).


  31. Manoj says:


  32. Ken ?-del says:

    For numeric values:


    where list = A1:A4 

    • Ken says:

      I need to retract my own post here guys. 

      It is WRONG! Let me explain.

      Suppose we have

      A1 = 1
      A2 = 0
      A3 = 2

      then Average = 1 and OFFSET(list,,,1,1) = 1
      so 1 = 1 but all the elements are NOT equal.


  33. Manoj says:


  34. Pavel Lasák says:

    =IF(A1=B1,IF(B1=C1,IF(C1=D1,TRUE,FALSE),FALSE),FALSE) ....

  35. Matthew Holbrook says:


  36. Parin Thacker says:

    I have a little more flexible approach. Suppose the value of 'n' is known. There is a possibility that only some of the cells in a row are filled up. For example if n = 10, then in a row, A1 to A10 must be compared. But in case only cells upto A7 are filled up. The formula thus has to adapt accordingly. Below formula does that:


  37. Ingo says:

    In A1:A100 is word/number
    In B1 is word/number we look

    C1=MAX(FREQUENCY(IF(A1:A100=B1,ROW(A1:A100)),IF(A1:A100<>B1,ROW(A1:A100))))  array formula

  38. Shubhro De says:

    We can use an array formula
    OR if we want n variable

  39. Steve LeLaurin says:


  40. Ariel says:

    I would use this one (simlpe)


  41. uri Weiss says:

    try this

  42. uri Weiss says:

    Olso try this
    Please notice it is an Array Formula

  43. elnur says:

    Dear All,
    i used that formula

  44. andy holaday says:

    Love the variety of responses.

    will return true if the input range has blank cells

    My personal fave is the array formula {=AND(A1=A1:A4)}. Short and sweet, and easy to read. Blank cells will tally as a mismatch.

    A close second is 
    which will throw an error if blanks are present. 


  45. mahesh says:

    =PRODUCT(B1:D1)=B1^COUNT(B1:D1)...will return TRUE or FALSE

  46. Prem Singh says:

    Dear Sir,
    My answer is =exact(a2,a1)

  47. jack corley says:


  48. Arshad says:

    Hello Chandoo,
    We can also use Conditional Formatting......

  49. Akash Khandelwal says:

    For Numerics..

    results in True/False.

  50. Manoj Gupta says:


  51. sam says:

    =AND(A1=A2:A4) array entered
    =AND(A1=A2:An) array entered

  52. shrivallabha says:

    will give value as 1 or 0

  53. James says:

    Hi there, here's a simple formula to determine not only whether all 4 cells (A1 --> A4) are equal, but also whether any of the cells are equal and identifies which cells they are ...


    A result of 1111 means no cells are equal, 4444 means all cells are equal, 1212 would mean there are 2 cells the same & they are in A2 & A4, etc

  54. Lood says:


    Obviously doesn't cover bonus question 1, but does so for q2 🙂

  55. Abhishek says:

    If formula

  56. Shmuel says:


  57. Faez says:

    Try this formula


  58. Werner says:

    I used the Swiss knife of excel: SUMPRODUCT, works for numeric as well as for non-numeric cell content and A1:A4 is obviously easily changed to any range.


    • roirraWedorehT says:

      All of the individual non-array formulas (didn't test the array ones) have one flaw or another - mostly specifically if all the columns are blank, the result would still be false.

      Another formula in the comments worked for these but didn't work for when all columns had "0.00" in them. My solution was to OR the two. If H3 through H149 have your values, then this is what worked for me:


      This solution puts "Blank" if all the rows are blank, otherwise, it puts whatever the value that's in all of the rows - "0.00" or whatever.

      Thanks for all the answers!

  59. Allan R says:

    I used a nested if statement which also showed, via the false message, the first instance of cells which were not equal for the cells a1 to a5.

    =IF(A1=A2, IF(A2=A3, IF(A3=A4, IF(A4 = A5, "True","False A4"), "False A3"), "False A2"))

  60. Shailesh says:


    First, let me begin by saying, I am a big fan of all your posts and read your emails, mostly on the same day as you send them. I have not replied as much as I wanted to.

    This is my first attempt at answering a question on your post

    I came up with a simple check which will test if all values in a range A1:An are same or not

    Assuming range you want to check is A1:A10,
    In Cell B1, insert the formula 

    =IF(COUNTIFS(A1:A10,A1)=COUNTA(A1:A10),"All cells are same","All cells are not same") 

    The idea I applied is counting total number of non-blank cells and then counting the number of cells which match cell A1. If these are same, then it means
    a) all cells have the same value! (All can be blank, then both counts will be zero)

    I am working on finding the range automatically 🙂

    Can extend this into VBA and use InputBox etc to generate some user interaction


  61. Chirag says:


  62. Rafaqat Ali says:

    For homework & Bonus Question 3



  63. Christopher A says:


  64. Sanjeev Sawal says:

    One possible solution could be =+IF(COUNTIF(A1:A4,A1)-COUNT(A1:A4)=0,1,0)
    where A1:A4 is data range which can be a dynamic range and the formula can be modified accordingly. 
    Sanjeev Sawal

  65. I got the right result with this one:


  66. SIVAKUMAR R says:


  67. SIVAKUMAR R says:



  68. VaraK says:

    =AND(A1:A3=A2:A4)..Confirm with Ctrl+Shift+Enter (As as array formula). Works well for Text values and large range of values as well.

  69. Istiyak says:

    suppose cells contain 2 values ==== Yes | no

    formula :
    It will return True or False.

    =IF((COUNTA(A1:A4)=COUNTIF(A1:A4,"yes")),"Same value","Mis-match")
    it will return Same Value OR Mis-match.

    Hope you like it.


  70. Suraj Nair says:

    Also can use this formula

  71. Antonio says:

    Let say the values are in the range $B$1:$E$1, then the formula is:


    Please check that:
    * $B$1 was used as pivot value and could be randomly selected
    * It works well if parenthesis is omitted for values "1" and "0"
    * This formula applies also to "n-values" and non-numeric values (text, logical, etc.)


  72. Jorrie says:

    Hi, first time trying to solve a probleme.
    New at this but really enjoying Chardoo.org

    Think the following will work in all 3 questions




  73. Ashok Variyani says:

    use below formula for to get True / False


    and use below formula for to get {1/0} or {match / Mismatch}

    =IF(COUNTA(A1:A4)=COUNT(A1:A4),{1,0} or {match,Mismatch})

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

  75. Cristian says:

    Hi, sorry if it's repeated, this array formula works well with numbers or text, the range can easily be dynamic: {=AND(A1:An=A1)} Now, after three days, I understand a lot more about array formulae, thanks?

  76. Adam says:


    • Yani says:

      What if there are not only four cells to compare but An?
      how will I determine if there is one cell that is not equal from any other cells?

  77. Netaji Bhopale says:


  78. Aniket says:


  79. frank says:

    how this formula works in excel (B4+E4)/50*20

  80. Jerome says:

    I'm a little late to the party, but I figured I'd post anyways.

    For numbers only:

  81. nazmul_muneer says:

    The formula given below will fulfill the all criteria including bonus questions



  82. venkat says:


  83. Naveen Kumar says:


    • Hui... says:

      You can simplify your formulas as below:
      Excel will return True or False without the need for the If() function

  84. Raghavendra says:

    Hi ,
    This question is similar to the one in the post.
    I have Text values in cell A1 and A2. 
    If A1 = A2, update 10 in cell A3 , else 0.
    Is there any formula for this. I am new to VB and hence do not have much knowledge. Eager to learn!!
    Thanks in advance !!!

  85. sandeep sharma says:


  86. sandeep sharma says:

    also =IF(AND(A1:A4=A1),TRUE,FALSE)

  87. Akshay says:

    One can use "IF, AND" formula.


  88. Cards says:


  89. Ritesh says:

    Enter array formula like, = IF($B$16:$B$21=$B$17:$B$22,"Yes","No")

  90. sunil gupta says:

    it can work try this one

  91. Andy Gore says:

    A question for you
    sheet 1 table A1:C10

    What formula in sheet 2 A1 will give me what is entered in the table sheet 1 A1:C10
    There is usually only one entry made in the table but if you can supply the answer to 1 or 2 entries I would be grateful

  92. Duncan says:


  93. Eduardo says:



    Both Return TRUE or FALSE

  94. kaushik says:

    =if({sum(1/countif($A$1:$A$n,A1:An)}=1,"All Same","Not All Same")

  95. manish gupta says:

    I use formula A1=B1 and get value of TRUE / FALSE in C1. I had dragged this formula for 10 rows. Now in cell D2 i tried to put formula..

    =if(and(c1="False", c2="true"), "conflict", "no conflict")

    but even when the condition is true i am still getting no conflict.

    Can you please advice?

    • Hui... says:

      Remove the " from around True and False
      =if(and(c1=False, c2=True), "conflict", "no conflict")

      In C1 and C2 you have a Boolean expression and it evaluates as True/False
      These are not text, although they do appear as Text, they are not 1/0 although they sometimes behave as 1/0, they are in fact Boolean values True/False

      So in your example you can simplify it as
      =If( And( Not(C1), C2), "conflict", "no conflict")

  96. Mohammed says:


  97. adivyom says:

    Answer to both bonus questions 2 and 3:


  98. Yves S says:

    answer to all questions:

    this works with numeric, non-numeric, and blanks:

    COUNT will not count numeric
    COUNTA will count blanks as one

  99. cnestg8r says:


    This will tell you how many unique values exist in the selected range. Text or numeric mixed.

  100. RAJIV SIROHI says:

    {=IF(AND(A1:A9=A2:A10),"EQUAL","NOT EQUAL")}

    this is an array formula, insert it with CSE.

  101. Anonymous Coward says:


Leave a Reply