How to Find and Highlight Duplicate Values in Range in Excel VBA?

In this post, you’ll be learning how to find and highlight duplicate values in Range in your excel spreadsheet using Excel VBA.

How to Find and Highlight Duplicate Values in Range in Excel VBA?

To find and highlight duplicate values in Range, first insert a command button in the page and enter the code.

How to Find and Highlight Duplicate Values in Range in Excel VBA?

Code:

Option Explicit

Sub Highlight_Duplicates(Values As Range)

Dim Cell

For Each Cell In Values

    If WorksheetFunction.CountIf(Values, Cell.Value) > 1 Then

        Cell.Interior.ColorIndex = 8

    End If

Next Cell

End Sub

Code for the Command  button:

Private Sub CommandButton1_Click()

Highlight_Duplicates (Sheets("Sheet1").Range("C10:F15"))

End Sub

Now Click the button, the highlighted cells contains the duplicate values.

How to Find and Highlight Duplicate Values in Range in Excel VBA?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...