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
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.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
After you've applied a conditional format to a cell, you may have a need to later delete that format so that the cell is ...
Discover MoreIt is easy to apply conditional formatting to a cell. What if you want an entire row to be formatted, however, based on ...
Discover MoreExcel provides a great conditional formatting capability that allows you to change how a cell appears based on critiera ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments