Comparing Two Ranges of Data and Returning a Single Value

Last reviewed: November 2, 1994
Article ID: Q66759

SUMMARY

You may want to compare two ranges of data to see whether or not the ranges are equal, and then return a particular value if they are equal. (That is, if every cell of one array equals every adjacent cell of another array, then you should return a particular value.)

For example:

   A1:  2  B1:  2  C1:  1
   A2:  3  B2:  3  C2:  2
   A3:  4  B3:  4  C3:  3
   A4:  1  B4:  1  C4:  4

You may want to compare the values in columns A and B. If all corresponding values are equal, you should return the sum of the values in column C. Typing {=IF(A1:A4=B1:B4,SUM(C1:C4))} does not work. This tests only cells A1 and B1 for equality and returns the SUM, even if all other values in columns A and B are inequal. To obtain the proper results, type the following:

   =IF(AND(A1:A4=B1:B4),SUM(C1:C4),"")

This is typical of any comparison where you want to apply a test to two ranges of cells and return a value in a single cell. Thus, most functions could be used in place of the SUM function above.


KBCategory: kbother
KBSubcategory:

Additional reference words: noupd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.