 # How to Compare Two Columns in Google Sheets (for Matches & Differences)

To err is human, and we all know that. When working with large amounts of data, the human eye is not very capable of identifying small differences or similarities between data items.

Thankfully, data processing software such as Google Sheets can pick up details that even the keenest human eye might miss.

As such, tasks like comparing columns, finding differences, and pointing out similarities get done easily, at lightning speeds, and without errors.

In this tutorial, we will show you how you can use Google Sheets to compare two columns and find matches and differences.

For each of the above topics, we will be using the following data sample, consisting of two columns – ingredients for Cake, and ingredients for Cookies: Also, note that in this case, we are comparing columns that are in the same worksheet. But you can as well use the same techniques to compare two columns that are in different Google Sheets documents. To do this you will have to use the IMPORTRANGE function to be able to refer to the columns in another sheet.

## How to Compare Two Columns for Exact Row Matches

The simplest way to compare two columns is to find exact row matches. All this calls for is just a row-by-row comparison.

Google sheets just need to see which rows have the same values and which ones have different values and display the result in a third, blank column.

In our example, we are simply going to create a new column for the results, and display a TRUE if the pair of items in the same row match and a FALSE if they don’t.

The formula you would use for a comparison like this is:

`=A2=B2`

The above formula compares data in row 2 of both columns to see if they match. If they do, then you get a TRUE result. If not, you get a FALSE result.

Here are the steps to follow:

1. In the second row of column C (in cell C2), insert the formula: =A2=B2
2. Press the return key.
3. Double click the fill handle to copy the same formula to the rest of the cells in column C.

You should now see the results of each comparison in column C. ## Compare Two Columns and Show Meaningful Text

The above method works great if you’re the only one who will be working with the data.

But, a third-person going through your worksheet might not understand what exactly you’re implying by the words “TRUE” and “FALSE”.

So it makes sense to give a more descriptive result in column C. For example, you could use the word “Matching” for row items that match and “Not matching” for row items that don’t match.

If you want to get a more descriptive result, you can use a simple IF formula to return the text “Match” when the values are the same and “Mismatch” when the values are different.

For this, assuming you were working in cell C2 of our example, you would use the following formula:

`=IF(A2=B2,"Matching","Not Matching")`

The above formula uses an IF function to compare values in A2 and B2. If the condition “A2=B2” is TRUE, it returns the text “Matching”. If not, it returns the text FALSE.

Here are the steps to follow:

1. In the second row of column C (in cell C2), insert the formula: =IF(A2=B2,”Matching”,”Not Matching”)
2. Press the return key.
3. Double click the fill handle to copy the same formula to the rest of the cells in column C.

You should now see the results of each comparison as “Matching” or “Not Matching” in column C. ## Compare Two Columns and Highlight Matching Rows

If instead of displaying results in a separate column, you would rather have rows with matching data highlighted, then you can perform Conditional Formatting.

Conditional formatting is a great technique that lets you format cells based on a condition.

Here’s how you can use Conditional formatting to highlight matching rows in Google Sheets:

2. Select the ‘Conditional Formatting’ option. 3. This will open the ‘Conditional format rules’ sidebar on the right of the window. 4. In the input box under “Apply to range”, type in the range of cells you want to compare. In our example, we can type A2:B12. 5. Next, in the Format rules section, under “Format cells if”, click on the dropdown arrow. 6. From the dropdown menu that appears, select “Custom formula is”. 7. You will see an input box below the dropdown list. Type your custom formula there: “=\$A2=\$B2”. 8. Under “Formatting style”, click on the Fill Color button. 9. Select the color you want to use, in order to highlight matching cells/rows. We selected “light cornflower blue 1”. 10. Finally click the Done button, to let Conditional formatting do its work. You should now see all matching cells/rows highlighted in your selected color. Note: In case you want to do the opposite, i.e. to highlight only the cells/rows that don’t match, change the formula in step 7 to: =\$A2<>\$B2 ## Compare Two Columns to Find Matching Data

So far, the techniques we discussed mainly found out if cells in the same row were matching.

But what if you want to compare two columns and find out which values of column A are repeating in column B, irrespective of which row it’s in?

That would make more sense for our sample data too wouldn’t it? You might want to know which ingredients of a cake are also used in baking cookies.

Here’s how you can use Conditional formatting to find duplicate data:

2. Select the ‘Conditional Formatting’ option.
3. This will open the ‘Conditional format rules’ sidebar on the right of the window.
4. In the input box under “Apply to range”, type in the range of cells you want to apply the formatting on. In our example, we want to see the highlights of column B only. So we type: B2:B12. 5. Next, in the Format rules section, under “Format cells if”, click on the dropdown arrow.
6. From the dropdown menu that appears, select “Custom formula is”.
7. You will see an input box below the dropdown list. Type your custom formula there: =COUNTIF(\$A\$2:\$A\$9,B2)>0 8. Under “Formatting style”, click on the Fill Color button ( ).
9. Select the color you want to use, in order to highlight matching cells/rows. We selected “light cornflower blue 1”.
10. Finally click the Done button, to let Conditional formatting do its work.

You should now see all cells (ingredients) of column B (cookies) that are also present in column A (cake) highlighted in your selected color. ### Explanation of the Formula

In this problem, we wanted to know which ingredients of column B also had an occurrence in column A.

In other words, we wanted to highlight only those items of column B that have 1 or more occurrences in cells A2 to A9.

In the formula:

`=COUNTIF(\$A\$2:\$A\$9,B2)>0`

The COUNTIF function counts the number of times the value in B2 occurs in the cell range A2:A9.

If this count is more than 0, it means a duplicate of the B2 value exists in column A. It could exist once, twice or more times. In either case, as long as the count is more than 0, the function returns a TRUE.

When the function returns a TRUE value, our conditional formatting gets to work and highlights cell B2.

This is repeated for all cells starting from B2 to B12.

## Compare Two Columns to Find Missing Data

Now, what happens when you want to do the opposite? What if you want to find the ingredients of Cookies that are not present in the Cake? In this case, you would only have to make a slight change to the formula used in step 7 of the previous method.

The Custom formula used in the Conditional format rule sidebar should now be:

`=COUNTIF(\$A\$2:\$A\$9,B2)=0` This is because you now want to see if the element of column B has 0 occurrences in column A.

This will give you the result as shown below: These were some of the ways in which you can use Google Sheets to compare two columns. We used a smaller sample to help you understand the concepts.

But the methods discussed in this tutorial can be really powerful when used with larger datasets, especially if you’re using it for analytical processing.

We encourage you to apply and experiment with these methods and hope you found the explanations helpful.

Other Google Sheets tutorials you may like: