Skip to footer content
EXCEL TOOLS

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide

Written by the team at Iron Software. If you are looking to automate your spreadsheet tasks programmatically, be sure to visit the IronXL product page to learn more about our professional Excel library for .NET.

In professional data management, maintaining information integrity is essential. Data redundancy, commonly presented as duplicate entries, can significantly compromise the accuracy of analytical models, financial reporting, and database synchronization. Whether you're managing an extensive client list or auditing a complex general ledger, knowing how to highlight duplicates in Excel is a fundamental skill for ensuring high-quality, actionable data.

The quickest way to identify these redundancies is through Excel's built-in Conditional Formatting feature engine. By selecting your data range and using the keyboard sequence Alt -> H -> L -> H -> D, You can trigger the Duplicate Values dialog to instantly. This allows you to apply a visual layer to your spreadsheet that highlights every instance of repeated data without altering the underlying values.

Method 1: The Quickest Way (Ribbon-Based Conditional Formatting)

For the vast majority of tasks, you don't need complex formulas or scripts. Excel provides a dedicated GUI tool specifically designed to scan for identical values within a selected range of cells.

Using the Ribbon Interface to Highlight Values

  1. Select your target range: Click and drag over the cells you wish to analyze. Alternatively, you can click a column header (e.g., Column A) to select the entire column of data.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 1 - Selected cells

  1. Navigate to the Home tab on the top ribbon.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 2 - Navigate to home tab

  1. Click Conditional Formatting in the styles group

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 3 - Conditional Formatting options in the styles group

  1. Select Highlight Cell Rules and then click Duplicate values to highlight duplicates in the given range.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 4 - Highlight Cell Rules options

  1. In the dialog box that appears, ensure that the left dropdown is set to Duplicate. Choose your preferred formatting style (e.g., "Light Red Fill with Dark Red Text") and click OK.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 5 - Setting custom Conditional Formatting rules

Using the Keyboard Shortcut

If you prefer to keep your hands on the keyboard, use the following sequence in order:

  1. Alt: Activates the Ribbon shortcuts.

  2. H: Selects the Home tab.

  3. L: Opens the Conditional Formatting menu.

  4. H: Selects Highlight Cell Rules.

  5. D: Opens the Duplicate Values dialog.

Example of Highlighted Duplicate Values

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 6 - Example output for how to highlight duplicates in Excel

Method 2: Custom Formula Highlighting (COUNTIF function)

The standard "Duplicate Values" tool is excellent for simple checks, but it lacks granularity. If you need to highlight values only if they appear more than twice, or if you need to highlight an entire row based on a single column's data, you must use a logical formula.

The Logic Behind using a Formula to Highlight Duplicate Entries

We use the COUNTIF function to determine the frequency of a value within a range. If the frequency is greater than 1, the condition returns TRUE, and the formatting is applied.

Steps to Implement:

  1. Select the data range starting from the first record (e.g., A2:A500).

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 7 - Select cell data range

  1. Go to Home > Conditional Formatting > New Rule.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 8 - Go to New Rule

  1. Select Use a formula to determine which cells to format.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 9 - Use a formula to find duplicates

  1. In the formula bar, enter:
=COUNTIF($A$2:$A$500, A2) > 1
=COUNTIF($A$2:$A$500, A2) > 1
The provided C# code snippet seems to be a fragment of an Excel formula rather than C# code. However, if you intended to convert a C# code snippet that uses a similar logic or functionality, please provide the complete C# code, and I will convert it to VB.NET for you.
$vbLabelText   $csharpLabel
  1. Click Format, choose your fill color under the Fill tab, and click OK.

Now, we can see that the duplicate rows are highlighted thanks our use of the above formula, making them easier to find.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 10 - Duplicated cells highlighted

Why use a formula?

By changing the integer at the end of the formula, you can create more specific rules. For instance, if you only care about "extreme" duplicates (items appearing 5 or more times, for example), you would use:

=COUNTIF($A$2:$A$500,A2) ≥ 5
=COUNTIF($A$2:$A$500,A2) ≥ 5
The provided C# code snippet appears to be incomplete or incorrect as it seems to be a fragment of an Excel formula rather than C# code. If you intended to provide a C# code snippet that involves a similar logic or operation, please provide the complete and correct C# code for conversion to VB.NET.
$vbLabelText   $csharpLabel

Method 3: Highlight Duplicate Data Based on Multi-Column Criteria

Often, a duplicate isn't defined by a single cell, but by a combination of cells or multiple criteria. For example, you might have two customers named "John Smith," but they are only "duplicates" if they also share the same "Zip Code."

The Concatenation Trick (Helper Column)

  1. Create a "Helper Column" next to your data.
  2. Use the ampersand (&) to combine the columns: =$A2 & $B2.
  3. Apply the Method 1 highlight to this new helper column.

The Advanced Formula Approach

If you don't want to add extra columns, you can use a $COUNTIFS$ (plural) formula within Conditional Formatting:

  1. Select your data range.
  2. Go to Conditional Formatting > New Rule > Use a formula... 3. Enter the following formula (assuming Name is in A and Zip is in B):
=COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2)>1
=COUNTIFS($A$2:$A$9,$A2,$B$2:$B$9,$B2)>1
This C# code appears to be a fragment of an Excel formula rather than a complete C# statement. However, if you want to use this logic in VB.NET, you would typically use Excel Interop or a library like EPPlus to interact with Excel files. Below is an example of how you might write a similar logic in VB.NET using Excel Interop:

net

This code assumes you have a reference to the Microsoft Excel Object Library in your project. Adjust the workbook path and sheet index as necessary for your specific use case.
$vbLabelText   $csharpLabel
  1. Set your format. Excel will now only highlight rows where both the name and the zip code match another entry in the list.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 11 - Highlighted duplicate data based off multiple criteria

Method 4: Highlighting Entire Rows Based on Column Duplicates

A common professional requirement is to highlight the entire row when a specific unique identifier (like an invoice ID or employee number) is duplicated. The standard tool won't do this; it only highlights the cell itself.

  1. Select your entire table (excluding headers). Ensure your active cell (the one that stays white in the selection) is in the first row of your data.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 12 - Selected table

  1. Open Conditional Formatting > New Rule > Use a Formula... 3. Assume your "Duplicate Check" column is Column A. Enter the following formula:
=COUNTIF($A$2:$A$9,$A2)>1
=COUNTIF($A$2:$A$9,$A2)>1
This C# code snippet appears to be a fragment of an Excel formula rather than a complete C# code. However, if you are looking to convert a similar logic into VB.NET code, you might be dealing with a scenario where you need to check if a value appears more than once in a range. Here's how you might write a similar logic in VB.NET:

net

This assumes you are working within an Excel interop context in VB.NET. If this is not what you intended, please provide more context or clarify the request.
$vbLabelText   $csharpLabel

Note: the dollar sign ($) before the 'A' is critical. It anchors the formula to Column A while allowing the row number to change as Excel checks the rest of your table.

  1. Choose your formatting and apply.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 13 - Table with duplicate values highlighted

Method 4: Finding Unique Values (The Reverse Highlight)

Sometimes, the goal isn't to find the duplicates, but to identify the "orphans", the values that appear only once. This is vital for reconciliation tasks where you are looking for missing entries or one-off transactions.

  1. Select the range you want to highlight.
  2. Go to Conditional Formatting > Highlight Cell Rules > Duplicate Values...

    1. In the left-hand dropdown, change "Duplicate" to Unique.

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 14 - Find unique values

  1. Select a contrasting color (e.g., Green Fill) to distinguish them from the rest of your data set.

Output for Our Rule to Check Unique Records vs. Duplicate Values

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 15 - Data with highlighted unique values

Method 5: VBA Macro for Frequent Audits

If you find yourself highlighting duplicates daily across multiple workbooks, a small VBA (Visual Basic for Applications) macro can automate the process. This is the most "technical" way to handle the task within Excel without moving to external code.

  1. Press Alt + F11 to open the VBA Editor.

  2. Go to Insert > Module.
  3. Paste the following code:
Sub HighlightDuplicates()
    Dim Rng As Range
    Set Rng = Selection
    Rng.FormatConditions.AddUniqueValues
    Rng.FormatConditions(Rng.FormatConditions.Count).SetFirstPriority
    Rng.FormatConditions(1).DupeUnique = xlDuplicate
    With Rng.FormatConditions(1).Font
        .Color = -16383844
    End With
    With Rng.FormatConditions(1).Interior
        .Color = 13551615
    End With
End Sub
Sub HighlightDuplicates()
    Dim Rng As Range
    Set Rng = Selection
    Rng.FormatConditions.AddUniqueValues
    Rng.FormatConditions(Rng.FormatConditions.Count).SetFirstPriority
    Rng.FormatConditions(1).DupeUnique = xlDuplicate
    With Rng.FormatConditions(1).Font
        .Color = -16383844
    End With
    With Rng.FormatConditions(1).Interior
        .Color = 13551615
    End With
End Sub
Option Strict On



Sub HighlightDuplicates()
    Dim Rng As Range
    Rng = Selection
    Rng.FormatConditions.AddUniqueValues()
    Rng.FormatConditions(Rng.FormatConditions.Count).SetFirstPriority()
    Rng.FormatConditions(1).DupeUnique = xlDuplicate
    With Rng.FormatConditions(1).Font
        .Color = -16383844
    End With
    With Rng.FormatConditions(1).Interior
        .Color = 13551615
    End With
End Sub
$vbLabelText   $csharpLabel
  1. Close the editor. You can now select any range and run this macro to apply the red highlight instantly.

Common Issues and Troubleshooting

Even with the correct settings, you may find that Excel fails to highlight duplicates or highlights cells that appear unique. This usually stems from data formatting inconsistencies.

1. Leading and Trailing Spaces

Excel treats "Data" and "Data " as two different values. If your information was exported from a CRM or web database, it likely contains invisible spaces.

  • Solution: Use the =TRIM() function in a helper column to clean the text before running your duplicate check.

2. Numbers Stored as Text

A cell containing the number $100$ will not match a cell containing the text "100".

  • Solution: Select the column, go to the Data tab, select Text to Columns, and click Finish. This usually forces Excel to re-evaluate the data types.

3. Case Sensitivity

Excel’s standard duplicate tool is not case-sensitive. It treats "APPLE" and "apple" as the same. If your workflow requires case-sensitive matching (e.g., for case-sensitive passwords or IDs), you must use a formula combining $SUMPRODUCT$ and $EXACT$:

=SUMPRODUCT(--EXACT($A$2:$A$500,A2))>1
=SUMPRODUCT(--EXACT($A$2:$A$500,A2))>1
The provided C# code appears to be a fragment of an Excel formula rather than C# code. If you intended to convert a C# code snippet, please provide the correct C# code. If this is indeed an Excel formula, it does not translate directly to VB.NET code, as it is specific to Excel's formula language. Please clarify your request if needed.
$vbLabelText   $csharpLabel

4. Non-Breaking Spaces

Common in data copied from the web, the "non-breaking space" (ASCII 160) is not removed by the standard TRIM function.

  • Solution: Use Find and Replace (Ctrl+H). Hold Alt and type 0160 on the number pad in the "Find" box, then leave "Replace" empty and click Replace All.

Beyond Highlighting: Removing Duplicates

Once you highlight duplicate rows, you may want to delete the duplicate data.

  1. Go to the Data tab.

  2. In the Data Tools group, click Remove Duplicates.

  3. Select which columns must match for a row to be considered a duplicate.

Warning: This action is permanent. Always keep a backup of your original data before running this tool.

For Developers: Automating Duplicate Detection with IronXL

While Excel’s GUI is sufficient for manual data entry, enterprise-level applications often require these checks to happen programmatically. If you are building a .NET application that processes user uploads or generates reports, manual clicking isn't an option.

IronXL allows developers to manipulate Excel files with full control over styles and formatting without the overhead of Microsoft Office Interop. You can perform high-speed scans for duplicates and apply conditional formatting directly via C# code.

Why Use IronXL for Data Auditing?

  • Performance: Scans millions of cells significantly faster than the Excel GUI.
  • Automation: Integrate duplicate checking into your CI/CD pipeline or backend services.
  • Format Control: Programmatically apply hex-code colors, borders, and fonts to duplicate records.

Code Snippet: Identifying Duplicates in C#

The following example demonstrates how to load a spreadsheet, identify repeated values in a specific column, and apply a visual highlight.

using IronXL;
using System.Linq;
// Load your workbook
WorkBook workbook = WorkBook.Load("Quarterly_Report.xlsx");
WorkSheet sheet = workbook.DefaultWorkSheet;
// Define the range you want to check (e.g., Column B)
var range = sheet["B2:B1000"];
// Identify duplicate values using LINQ logic
var duplicateValues = range.GroupBy(cell => cell.Value.ToString())
                           .Where(group => group.Count() > 1)
                           .Select(group => group.Key);
// Iterate through the range and apply a "Duplicate" style
foreach (var cell in range)
{
    if (duplicateValues.Contains(cell.Value.ToString()))
    {
        cell.Style.BackgroundColor = "#FFC7CE"; // Light Red
        cell.Style.Font.Color = "#9C0006";       // Dark Red
    }
}
// Save the workbook with highlighted duplicates
workbook.SaveAs("Audited_Report.xlsx");
using IronXL;
using System.Linq;
// Load your workbook
WorkBook workbook = WorkBook.Load("Quarterly_Report.xlsx");
WorkSheet sheet = workbook.DefaultWorkSheet;
// Define the range you want to check (e.g., Column B)
var range = sheet["B2:B1000"];
// Identify duplicate values using LINQ logic
var duplicateValues = range.GroupBy(cell => cell.Value.ToString())
                           .Where(group => group.Count() > 1)
                           .Select(group => group.Key);
// Iterate through the range and apply a "Duplicate" style
foreach (var cell in range)
{
    if (duplicateValues.Contains(cell.Value.ToString()))
    {
        cell.Style.BackgroundColor = "#FFC7CE"; // Light Red
        cell.Style.Font.Color = "#9C0006";       // Dark Red
    }
}
// Save the workbook with highlighted duplicates
workbook.SaveAs("Audited_Report.xlsx");
Imports IronXL
Imports System.Linq

' Load your workbook
Dim workbook As WorkBook = WorkBook.Load("Quarterly_Report.xlsx")
Dim sheet As WorkSheet = workbook.DefaultWorkSheet

' Define the range you want to check (e.g., Column B)
Dim range = sheet("B2:B1000")

' Identify duplicate values using LINQ logic
Dim duplicateValues = range.GroupBy(Function(cell) cell.Value.ToString()) _
                           .Where(Function(group) group.Count() > 1) _
                           .Select(Function(group) group.Key)

' Iterate through the range and apply a "Duplicate" style
For Each cell In range
    If duplicateValues.Contains(cell.Value.ToString()) Then
        cell.Style.BackgroundColor = "#FFC7CE" ' Light Red
        cell.Style.Font.Color = "#9C0006"       ' Dark Red
    End If
Next

' Save the workbook with highlighted duplicates
workbook.SaveAs("Audited_Report.xlsx")
$vbLabelText   $csharpLabel

Output

How to Highlight Duplicates in Excel: A Complete Step-by-Step Guide: Image 16 - Modified file with duplicates highlighted

Comparison of Duplicate Detection Methods

| Method | Best For | Data Size | Skill Level | | --- | --- | --- | --- | | Ribbon Tool | Quick, visual "one-off" checks. | Small/Medium | Beginner | | $COUNTIF$ | Specific thresholds (> 2 appearances). | Medium | Intermediate | | Entire Row Formula | Making tables readable during audits. | Medium | Intermediate | | Power Query | Heavy datasets and ETL workflows. | Large | Advanced | | VBA Macro | Repeating the same check on local files. | Medium | Advanced | | IronXL (.NET) | Building apps that process user files. | Unlimited | Developer |

Summary and Best Practices

Maintaining a duplicate-free environment is an ongoing process rather than a one-time task. To ensure the highest level of data accuracy, follow these industry best practices:

  1. Always Validate First: Before highlighting, use the TRIM and CLEAN functions to ensure your data is "normalized."

  2. Use Visual Cues: Use Conditional Formatting while entering data to catch errors in real-time.

  3. Audit Before Deleting: Never use "Remove Duplicates" until you have visually inspected the highlights. Some "duplicates" may be legitimate (e.g., two different orders from the same customer on the same day).

  4. Automate When Possible: If you are performing the same cleanup every Monday morning, consider using a VBA macro or a programmatic solution like IronXL to save hours of manual labor.

Ready to take your Excel skills to the next level? Whether you're a data analyst or a software engineer, having the right tools for the job is essential. Try IronXL’s free trial and discover how easy it is to manage complex spreadsheet logic with code.

Jordi Bardia
Software Engineer
Jordi is most proficient in Python, C# and C++, when he isn’t leveraging his skills at Iron Software; he’s game programming. Sharing responsibilities for product testing, product development and research, Jordi adds immense value to continual product improvement. The varied experience keeps him challenged and engaged, and he ...
Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me