+ Reply to Thread
Results 1 to 4 of 4

VBA Highlight Dupes in a Group

Hybrid View

  1. #1
    Registered User
    Join Date
    09-30-2003
    Posts
    3

    VBA Highlight Dupes in a Group

    I have data that is sorted in Column A by an ID number. Each ID number is duplicted multiple times and has data associated with it in column B. If in the duplicated ID numbers column B has duplicate value then highlight it.

    Thanks in advance.

    Dups in a group.xls

  2. #2
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: VBA Highlight Dupes in a Group

    maybe
    Sub colors()
    Dim a, i As Long
    
    a = Cells(1).CurrentRegion
    For i = 2 To UBound(a, 1)
       If a(i, 1) & Chr(2) & a(i, 2) = a(i - 1, 1) & Chr(2) & a(i - 1, 2) Then
            Cells(i - 1, 1).Resize(2, 2).Interior.Color = vbYellow
        End If
    Next i
    
    End Sub

  3. #3
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: VBA Highlight Dupes in a Group

    Kalak, that's pretty cool. I'm going to have to spend some time studying Resize. I always forget about it.

    Here's a long version.

    Sub FindDups()
    Dim WS As Worksheet
    Dim aCell As Range
    Dim LastRow As Long
    
        Set WS = ActiveWorkbook.Worksheets(1)
    
        With WS
            LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    
            For Each aCell In WS.Range("A1:A" & LastRow)
                If aCell & aCell.Offset(, 1) = aCell.Offset(1, 0) & aCell.Offset(1, 1) Then
                    .Range(aCell.Address, aCell.Offset(1, 1).Address).Interior.Color = 65535
                End If
            Next
        End With
    End Sub
    David
    (*) Reputation points appreciated.

  4. #4
    Registered User
    Join Date
    09-30-2003
    Posts
    3

    Re: VBA Highlight Dupes in a Group

    Thanks fellows for your help! Appreciate it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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