Compare Two Sheets for Duplicates with Conditional Formatting

Bottom Line: Learn how to compare two worksheets for duplicate values by highlighting the cells with conditional formatting.  Also highlight values in a different color when there are more than two duplicates.

Skill Level: Intermediate

Watch the Tutorial

Watch on YouTube & Subscribe to our Channel

Download the Excel File

Here are both the BEFORE and AFTER files from the tutorial.


Highlighting Duplicates Between Worksheets

Let's say you have two Excel worksheets that have overlapping data and you want to call attention to any cells that have duplicate entries. You can do so using a formula and conditional formatting.

Compare worksheets and highlight duplicate entries
Click to enlarge

First let's look at how to write the formula and then we will see how to apply the conditional formatting.

Use the COUNTIF Formula

The formula we'll write is going to examine a cell to see if its contents can be found in another range that we specify. If so, it will return a value of the number of times that data is found. For this process we are using the COUNTIF function.

COUNTIF has two arguments. The first is range and the second is criteria. Range is the group of cells that you want to look in to find a specific value. In my video tutorial, my range is from B2 to F1001 on the “Historical” sheet.

The criteria argument is simply the value that we are looking for. In our example, that's cell B2.

If the value that is found in cell B2 is also found in our designated range on the Historical tab, the COUNTIF function will return a number greater than zero. If it is NOT found on that sheet, it will return a zero.

With conditional formatting, we use those numbers to highlight the entries that are duplicates.

For our example, the formula looks like this:


It's important that the B2 used for the criteria argument is expressed as a relative reference, not an absolute reference. That's because when we apply the conditional formatting to our entire table, Excel will examine each cell individually to see if the criteria apply, but only if it's expressed as a relative reference (no dollar symbols in the reference).

COUNTIF formula

Applying Conditional Formatting

Now that we've looked at how the formula works, let's see how the conditional formatting is applied.

First select the entire range of cells that you want the formatting applied to. In our case it is all of the phone numbers on the “Current” worksheet. On the Home tab of the ribbon, choose the Conditional Formatting drop-down menu and select New Rule.

In the New Formatting Rule window, select the option that says Use a formula to determine which cells to format. That will open a field where you can write or paste the formula that we talked about above.

New Formatting Rule Window with COUNTIF Formula

Next, select the Format… button and that will open the Format Cells window, where you can select any type of formatting you wish. Change the font, border, number type, or fill with color so that your duplicates will stand out. When you hit OK, and OK again, your formatting will be applied.

Format Cells Window Select the formatting of your choice

Any cell that returns a value larger than zero will have the new formatting applied.

Conditional formatting applied to duplicate entries

Different Formatting for Multiple Duplicates

If you'd like to highlight in a different color the entries that have more than one duplicate in the other sheet, you can simply add a new rule.

Start by reopening the Conditional Formatting Rules Manager (Home tab → Conditional FormattingManage Rules). We're going to select the rule we've already made and then hit Duplicate Rule. Once the rule is duplicated, select one of them and hit Edit Rule.

The only change we will make to the rule is to add “>1” to the end of the rule. Then we can select Format to choose a different color.

conditional formatting rules manager duplicate entries
Click to enlarge

After hitting Apply, we see that our table now shows entries which have more than one duplicate in a different color:

Conditional formatting for multiple duplicates

Additional Tutorials

If you'd like to learn more about using conditional formatting, I think you'll find these two posts useful. Check them out:


As you can imagine, there are lots of uses and ways to expand this idea of comparing two sheets and using conditional formatting to highlight those comparisons. If you have any questions or ideas along those lines, I'd love to hear them in the comments below. I hope this was helpful for you.

Have a great day!

  • Great instruction. Would be an added benefit if you could list the phone numbers down a column and return every name that had that number.

  • Hi Jon! Wonderful information as always! In the particular case of phone numbers, occasionally we see people enter in different formats or even skip the area code. I was wondering if there is a way to use Conditional Formatting to identify cells that do not meet a certain value type (e.g. identify all cells that do not have a ###-###-#### structure). Is that at all possible? Or would you need helper columns in order to do this?

  • Hi John, I wish to thank you so much for sharing these great skills. Personally, I found this practically helpful.

    But I also have one question, I wish to create a data sheet and set a condition where by NO DUPLICATE ENTRIES will be allowed. How do I go about it?

    • I do not know if you can do that without using an ‘Input Macro’. One issue is if others are using the the database and it just rejects the number it would be very frustrating, they would think they are doing something wrong. The color change, most often, is best as an alert and then you can decide what course of action to take, delete or keep.
      Hope this helps.

  • Hi, Jon, thank you for the tutorial! I used Table references rather than cell references in my COUNTIF statement but the conditional formatting doesn’t seem to accept Table references. Is that true?

    • Jon made a relevant comment after a blog video from Feb 10th: “I should have mentioned that the Conditional Formatting Manager will not let you reference Tables (structured references) in formulas. However, Diane mentioned a workaround in her comment on creating the named range for the table. Then referencing the named range in the formula.”

  • Jon, is there a product that will find the duplicate photos saved on a computer. If not, I think you should figure out how to do that, I would buy the product. Thanks

  • Hi Jon thanks for this I am thinking I could use this to reconcile two sets of data for accounting purposes, anything that was not highlighted was a discrepancy?

  • I learned about this only recently, this was a nice reminder. I just started a movie database of my collections and this would work well to show which movies have the same actors in them.
    As always Jon, you are making me think, thanks for the seeds.

  • In the window Conditional Rules Formatting Manager on the right there are check boxes to Stop if True. My understanding is that if the box is not checked, after that rule is run, then the next rule is run in order of display. In this case would not all of the orange fills be then replaced with yellow fills since any number not zero would evaluate as true? What am I missing here? Thank you for your help.

  • Search
    Generic filters
    Exact matches only


    Learn 10 great Excel techniques that will wow your boss and make your co-workers say, "how did you do that??"
    Plus weekly updates to help you learn Excel.

    Download the eBook

    Excel Shortcuts List

    keyboard shortcuts list banner

    Learn over 270 Excel keyboard & mouse shortcuts for Windows & Mac.

    Excel Shortcuts List

    Join Our Weekly Newsletter

    The Excel Pro Tips Newsletter is packed with tips & techniques to help you master Excel.

    Join Our Free Newsletter

    About Me

    Jon Acampora Profile

    Hello and welcome! My name is Jon Acampora and I'm here to help you learn Excel.

    This blog is updated frequently with Excel and VBA tutorials & tools to help improve your Excel skills and save time with your everyday tasks. Subscribe above to stay updated. More about me...


    Free Excel Training Webinar Modern Power Tools