HomeMicrosoft OfficeExcelHow to Find and Highlight Duplicate Values in Range in Excel VBA?

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 article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021