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

Picking a Contiguous Range of Table Cells

Creating a table in Word is a relatively simple task. When you want to format or edit information in the table, often the ...

Discover More

Tabbing from One Table to the Next

Press the Tab key in a table, and Word dutifully moves to the next cell in that table. Press it in the last cell of a ...

Discover More

Dynamic Data Based on Chart Changes

Change the data on which a chart is based and Excel obligingly updates the chart to reflect the change. What if you want ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Conditional Page Breaks

Need to have your worksheet printout start on a new page every time a value in a column changes? There are a couple of ...

Discover More

Comparing Dollar Values in a Conditional Formatting Rule

Comparing values (like is done in conditional formatting rules) can yield some crazy results at times. This tip looks at ...

Discover More

Conditionally Formatting for a Pattern

Conditional formatting is a great tool you can use to customzie your worksheets. When you want to test whether a value in ...

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 two more than 7?

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.