Finding Duplicate Data Across Worksheets

Written by Allen Wyatt (last updated August 24, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


4

Tzvi has a workbook that has multiple worksheets containing names and addresses. He can use conditional formatting to highlight duplicate data on a single worksheet. He wonders, though, if there is a way to highlight duplicate data appearing on multiple worksheets. For instance, if a customer name appears on the first worksheet and on the fourth worksheet in the workbook, is there a way to highlight them?

There are a couple of ways you can approach this issue. One way, of course, is to simply merge the data from your worksheets into a single worksheet, and then use conditional formatting to highlight duplicates on that one worksheet, as you are already know how to do.

If you don't want to merge the worksheet data, then you could use conditional formatting, but it would take a bit of time. First, let's make some assumptions—your data is contained in Sheet1, Sheet2, Sheet3, and Sheet4. The customer names are in a single column (column A).

The first step is to display each worksheet, in turn, select the cells in column A, and then set a conditional formatting rule that highlights duplicates. This takes care of any duplicates that may exist on the worksheets themselves.

Next, go to Sheet1, select the cells in column A, and define a new conditional formatting rule that uses a formula to determine which cells to format. Here is the formula that should be in the rule:

=COUNTIF(Sheet2!$A:$A,A1)+COUNTIF(Sheet3!$A:$A,A1)+COUNTIF(Sheet4!$A:$A,A1) > 0

This rule checks the contents of column A in Sheet1 against those in the other three worksheets. You then need to set up a similar rule in the other worksheets, making sure that the formula refers to the other worksheets in the workbook.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7837) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Previous Column Values in a Drop-Down List

Want a quick way to add non-unique values into a column? You probably know you can do this by starting to simply type in ...

Discover More

Deleting Footnotes and Endnotes

Deleting either footnotes or endnotes is a simple process. Just select the reference mark and delete it. Assuming you are ...

Discover More

Errors When Subtracting

When you subtract two numbers from each other, you have a certain expectation of what Excel should deliver. What if you ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Stopping a Conditional Formatting Rule from Breaking into Smaller Ranges

When you paste information into a row that is conditionally formatted, you may end up messing up the rules applied to ...

Discover More

Shading Rows with Conditional Formatting

If you need to shade alternating rows in a data table, you'll want to examine how you can accomplish the task with ...

Discover More

Defining a Single Conditional Formatting Condition

Conditional formatting is a powerful tool you can use to dynamically adjust the formatting of your worksheet. This tip ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

2024-09-20 12:23:55

J. Woolley

@fred potter
Bravo. Clever macro.


2024-09-20 00:56:19

fred potter

How about a macro? Something like this could work for you:

Sub HiLiteDuplicates()
Dim Cel As Range
Dim Ws As Worksheet

With CreateObject("scripting.dictionary")
For Each Ws In Worksheets
Ws.UsedRange.Interior.ColorIndex = xlNone
For Each Cel In Ws.UsedRange
If Cel.Value <> "" Then
If Not .Exists(Cel.Value) Then
.Add Cel.Value, Cel
Else
Cel.Interior.Color = 456789
.Item(Cel.Value).Interior.Color = 456789
End If
End If
Next Cel
Next Ws
End With
End Sub


2024-08-25 10:46:41

J. Woolley

COUNTIF does not support a 3D range reference like
    Sheet1:Sheet4!$A:$A
but My Excel Toolbox includes the following function:
    COUNTIF3D(FirstSheetRange, Criteria, [LastSheetRange])
Therefore, the Tip's formula can be replaced by this formula:
    =(COUNTIF3D(Sheet1!$A:$A,A1,Sheet4!$A:$A)-COUNTIF($A:$A,A1))>0
Notice the same formula can be applied to each worksheet's conditional format because it accounts for that sheet's duplicates. In fact, the separate conditional formatting rule that highlights duplicates on a sheet can be deleted if the following formula is used for each worksheet instead:
    =COUNTIF3D(Sheet1!$A:$A,A1,Sheet4!$A:$A)>1
A worksheet’s name must be surrounded by apostrophes if it includes a space or other special character.
To edit a rule's formula in the Conditional Formatting Rules Manager, first click Edit Rule..., then click within the formula and press F2 to enable cursor movement using the arrow keys, Home, End, etc.
For more on 3D range references, see https://excelribbon.tips.net/T011803
And see https://sites.google.com/view/MyExcelToolbox/


2024-08-24 08:36:41

Ron S

You can use PowerQuery to merge the tabs into a single tab, In PQ you can add a new column with the tab name. Then you can use CF to highlight duplicates. But, in PQ you could also simply remove the duplicates if that is what you need to do.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.