In this article, we will learn how to find duplicates in two lists that are opposite values in Excel. For example, if we have two lists of numbers, we want to identify the pairs that have the same absolute value but different signs, such as 5 and -5.
This task can be useful for various purposes, such as finding errors, inconsistencies, or anomalies in data sets. For instance, we might want to check if there are any transactions that have the same amount but opposite directions, such as a deposit and a withdrawal.
There are different ways to accomplish this task in Excel, depending on the size and structure of the data. In this article, we will explore three methods:
- Using the COUNTIF function
- Using the VLOOKUP function
- Using the MATCH function
We will explain the basic theory behind each method, the steps to apply them, and the advantages and disadvantages of each one. We will also provide a detailed example with real numbers and an Excel table to illustrate each method.
Method 1: Using the COUNTIF Function
The COUNTIF function counts the number of cells in a range that meet a certain criterion. We can use this function to find duplicates in two lists that are opposite values by using the following formula:
=COUNTIF(range,-value)
This formula returns the number of cells in the range that are equal to the negative of the value. If the result is greater than zero, it means that there is a duplicate in the range that is the opposite value of the value.
For example, if we have the following two lists in columns A and B:
A | B |
---|---|
5 | 3 |
2 | -4 |
-3 | 6 |
4 | -5 |
-6 | 2 |
We can use the following formula in cell C2 and copy it down to find the duplicates:
=COUNTIF($B$2:$B$6,-A2)
This formula returns the following results:
A | B | C |
---|---|---|
5 | 3 | 1 |
2 | -4 | 0 |
-3 | 6 | 1 |
4 | -5 | 1 |
-6 | 2 | 0 |
We can see that the formula returns 1 for the values that have a duplicate in the other list that is the opposite value, such as 5 and -5, and 0 for the values that do not have a duplicate, such as 2 and -4.
The advantage of this method is that it is simple and easy to use. The disadvantage is that it only works for numeric values, and it does not return the location or the value of the duplicate.
Method 2: Using the VLOOKUP Function
The VLOOKUP function looks up a value in the first column of a table and returns a corresponding value from another column in the same row. We can use this function to find duplicates in two lists that are opposite values by using the following formula:
=VLOOKUP(-value,table,column,FALSE)
This formula looks up the negative of the value in the first column of the table and returns the value from the specified column in the same row. If the value is not found, it returns an error. We can use the IFERROR function to handle the error and return a custom message, such as “Not a Match”.
For example, if we have the same two lists in columns A and B as before, we can use the following formula in cell D2 and copy it down to find the duplicates:
=IFERROR(VLOOKUP(-A2,$B$2:$B$6,1,FALSE),“Not a Match”)
This formula returns the following results:
A | B | D |
---|---|---|
5 | 3 | -5 |
2 | -4 | Not a Match |
-3 | 6 | 3 |
4 | -5 | -4 |
-6 | 2 | Not a Match |
We can see that the formula returns the value of the duplicate in the other list that is the opposite value, such as -5 for 5, and 3 for -3, and “Not a Match” for the values that do not have a duplicate, such as 2 and -6.
The advantage of this method is that it works for both numeric and text values, and it returns the value of the duplicate. The disadvantage is that it only works if the lookup value is in the first column of the table, and it does not return the location of the duplicate.
Method 3: Using the MATCH Function
The MATCH function returns the relative position of a value in a range. We can use this function to find duplicates in two lists that are opposite values by using the following formula:
=MATCH(-value,range,0)
This formula returns the row number of the cell in the range that is equal to the negative of the value. If the value is not found, it returns an error. We can use the IFERROR function to handle the error and return a custom message, such as “Not a Match”.
For example, if we have the same two lists in columns A and B as before, we can use the following formula in cell E2 and copy it down to find the duplicates:
=IFERROR(MATCH(-A2,$B$2:$B$6,0),“Not a Match”)
This formula returns the following results:
A | B | E |
---|---|---|
5 | 3 | 4 |
2 | -4 | Not a Match |
-3 | 6 | 1 |
4 | -5 | 2 |
-6 | 2 | Not a Match |
We can see that the formula returns the row number of the duplicate in the other list that is the opposite value, such as 4 for 5, and 1 for -3, and “Not a Match” for the values that do not have a duplicate, such as 2 and -6.
The advantage of this method is that it works for both numeric and text values, and it returns the location of the duplicate. The disadvantage is that it does not return the value of the duplicate, and it requires an additional step to retrieve the value from the corresponding cell.
Hi John, thanx for this.
What if there are duplicate -ve corresponding values, it will return duplicate the results. The issue i am trying to solve is this.
I have 2000 plus journal entries in the same col e.g. Col A contains both the +ve and the -ve offsetting value. I want to identify which +ve value has a -ve corresponding value so i dont add it to my calculation ie. they net off. The issue im having is that there exist +ve values with the same amount i.e. $10,000 . The formula returns the same -$10 000 alongside, so it appears all the $10,000 have a -ve corresponding value but in essence there is only ONE -ve $10,000 entry.
Sorry for the long winded explination, hope it makes sense.