+ Reply to Thread
Results 1 to 4 of 4

highlight duplicates in column when selected

  1. #1
    Registered User
    Join Date
    10-04-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    2

    highlight duplicates in column when selected

    Hi,
    I am simply trying to be able to select a cell and highlight all of the cells with duplicate text in the same column. If there are no duplicates, then I don't want any highlighting.
    Also if there is no text in the selected cell, then again, no highlighting.
    I have this working:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    bottomrow = Cells(Rows.Count, "E").End(xlUp).Row
    Set myrange = Range("E2:E" & bottomrow)
    For Each c In myrange
    If Target.Text = "" Or c.Text <> Target.Text Then
    c.Interior.ColorIndex = xlNone


    ElseIf c.Text = Target.Text Then
    c.Interior.ColorIndex = 19

    ElseIf c.Text <> Target.Text Then
    c.Interior.ColorIndex = 19

    End If
    Next

    End Sub


    The problem is that the active / selected cell itself is counted as a duplicate.
    So even if there are no duplicates in the column, the selected cell is highlighted.

    Do I have to test for Unique? If so how?

    Thanks
    -Doug
    Last edited by Doug W; 10-05-2011 at 10:53 AM.

  2. #2
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: highlight duplicates in column when selected

    Here's teh modified code.
    see attached example.
    modytrane

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: highlight duplicates in column when selected

    Doug, welcome to the forum,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Registered User
    Join Date
    10-04-2011
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: highlight duplicates in column when selected

    Thanks modytrane,

    I appreciate your help. Although your edit didn't do exactly what I needed, I was able to use your direction to deliver what I needed to have done.

    Your code removes the highlight of the selected cell but leaves the duplicates highlighted.
    I had gone through many iterations of modified code and got that result.

    The code below uses your c.Address and Target.Address and gives me the exact functionality I'm looking for.

    The idea is to be able to click on a cell in a column with a large number of rows and have the highlight on the selected cell tell me that somewhere in the column there is a duplicate. If the selected cell does not highlight, then I know there are no duplicates in the lengthy column.

    The selected cell no longer is considered a dupe (of itself) as with:
    Please Login or Register  to view this content.


    This works great:

    Please Login or Register  to view this content.
    Thanks again !!!
    -Doug W
    Last edited by Doug W; 10-05-2011 at 11:01 AM. Reason: Additional clarity

+ 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