Results 1 to 9 of 9

VBA to Highlight Duplicate Cells and Show Msg Box

Threaded View

  1. #1
    Registered User
    Join Date
    02-08-2021
    Location
    Michigan, USA
    MS-Off Ver
    O365
    Posts
    54

    VBA to Highlight Duplicate Cells and Show Msg Box

    I am trying to write a VBA code to highlight duplicate cells and show message box. The code I have below works but when a duplicate is entered only the first duplicate cell is highlighting in red and the message box shows. I want both cells to highlight red and show the message box. Any help on this is greatly appreciated.

    Private Sub Worksheet_Change(ByVal target As Range)

    Dim myRange As Range
    Dim i As Integer
    Dim j As Integer
    Dim myCell As Range

    Set myRange = Range("D1:D10")

    For Each myCell In myRange
    If WorksheetFunction.CountIf(myRange, myCell.Value) > 1 Then
    myCell.Interior.ColorIndex = 3
    GoTo DisplayMsg

    ElseIf WorksheetFunction.CountIf(myRange, myCell.Value) = 1 Or WorksheetFunction.CountIf(myRange, myCell.Value) = 0 Then
    myCell.Interior.ColorIndex = 0

    End If

    Exit Sub

    Next

    DisplayMsg:
    MsgBox "Duplicate URL's entered are highlighted in red"


    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Highlight all duplicate cells ignoring blank cells
    By Vivek2705 in forum Excel General
    Replies: 10
    Last Post: 05-22-2024, 04:54 PM
  2. [SOLVED] Highlight cells that are duplicate pairs
    By erob223 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-22-2015, 10:46 AM
  3. [SOLVED] Find Duplicate - Highlight Cells
    By da80th in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 01-15-2013, 07:49 PM
  4. Highlight cells if duplicate found on the same row
    By martinez_pedro in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-23-2010, 04:24 AM
  5. Highlight Visible Duplicate Cells
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2010, 10:20 AM
  6. Highlight Duplicate Cells in Different Colors
    By dbla921 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-11-2008, 04:43 PM
  7. Highlight duplicate cells in next column...
    By ImpetuousRacer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-25-2008, 03:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1