
- #Highlight duplicates in excel how to
- #Highlight duplicates in excel windows 10
- #Highlight duplicates in excel code
- #Highlight duplicates in excel windows
The On Error statements catch keystrokes instead of a range selection.

#Highlight duplicates in excel code
Notice that the code isn’t case sensitive (Doris and doris). Those four cells are now yellow, which means two values have a duplicate: John and Doris. That’s it! As you can see in Figure C, the procedure found two duplicates. Click OK to close the information message that displays the number of duplicates, shown in Figure C.When prompted, select B3:B9 as shown in Figure B, and click OK.In the resulting dialog, choose HighlightDuplicates() as shown in Figure A and click Run.Use the proceduresĪfter entering the procedures, you’re ready to put them to work as follows: Doing so will remove any phantom web characters that might otherwise cause errors. Instead, copy the code into a text editor and then paste that code into the ThisWorkbook module. If you enter the code manually, don’t paste from this web page. In addition, the macro is in the downloadable. You can enter the code manually or import the downloadable. In the Project Explorer to the left, select ThisWorkbook so you can run the procedure in any sheet. To enter both procedures, press Alt + F11 to open the Visual Basic Editor.
#Highlight duplicates in excel windows
SEE: Windows 10: Lists of vocal commands for speech recognition and dictation (free PDF) (TechRepublic) If you’re using a menu version, you can skip this step. If you’re using a ribbon version, be sure to save the workbook as a macro-enabled file or the procedure won’t run. MsgBox “You have ” & j & ” duplicates.”, vbOKOnly If WorksheetFunction.CountIf(selRange, curCell.Value) > 1 Then ‘Cycle through user-selected range to highlight duplicates. & “Please select multiple contiguous cells ” _ Prompt:=”Select a range to check for duplicate values.”, _ ‘Must have Break on Unhandled Errors selected. If the range has a permanent fill color, you’ll want to accommodate that in Listing B by using that same fill color setting instead of 0. HighlightDuplicates() sets a highlight by setting the ColorIndex property to 36, which is yellow Listing B sets the same setting to 0, which is no fill color at all. Listing B is similar but removes highlights and doesn’t display the duplicate count. After checks on that selection, the code highlights duplicates and then displays the number of duplicates highlighted. After declaring and defining variables, the code prompts the user to select a range. Listing A highlights duplicate values in a data range. But some would choose to combine them, so it’s worth considering. You could combine the two into one procedure and prompt the user to identify whether the task is to highlight or remove highlighting, but that requires an extra click every time you run the procedure.
#Highlight duplicates in excel how to
How to use the VBA procedureīefore we review the procedures, it’s worth noting that code-wise, the two procedures are almost identical. This article assumes that you have basic Excel skills however, even a beginner should be able to follow the instructions to success.
#Highlight duplicates in excel windows 10
I’m using Microsoft 365 on a Windows 10 64-bit system, but you can use earlier versions.

SEE: 83 Excel tips every user should master (TechRepublic) This article also includes code to remove highlighting from a data range. In either case, this article will review VBA code that highlights duplicates in a data range. Or, more reasonably, users might not be savvy enough to apply a conditional formatting rule.


However, sometimes, you only want a quick look or count of duplicates you don’t want a permanent format. When the rule is TRUE, the format stays until the condition is FALSE or you remove the rule. There are many ways to find duplicates in a Microsoft Excel data range-conditional formatting being one of the most commonly used. Image: /Shutterstock Must-read Windows coverageĭefend your network with Microsoft outside-in security services When a conditional formatting rule is overkill, use these VBA procedures to highlight duplicates and then remove the highlighting in Microsoft Excel. How to use VBA to highlight duplicate values in an Excel spreadsheet
