Consulting

Results 1 to 8 of 8

Thread: Highlight duplicate value in a column

  1. #1
    VBAX Regular
    Joined
    Jan 2008
    Posts
    75
    Location

    Wink Highlight duplicate value in a column

    Hi All,

    I wrote the following VBA code to check for duplicates in a column in my worksheet, but it is not working. Please, I would be grateful if someone in the forum will help me out.

    [VBA]Function CheckforDuplicateBarcodes(columnname As Integer)
    Dim rowcount
    Dim R
    rowcount = Range("A65536").End(xlUp).Row
    For R = 2 To rowcount
    myCheck = ActiveCell
    If ActiveCell = myCheck Then
    Sheet1.Cells(R, columnname).Interior.ColorIndex = 5
    End If

    Next
    End Function

    Sub Duplibutton()
    CheckforDuplicateBarcodes (14)
    End Sub[/VBA]

    Thanks

    Lucpian

  2. #2

  3. #3

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Also take a look at the Duplicate Master add-in by brettdj, does what you are asking very, very well....


    http://members.iinet.net.au/~brettdj/

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why not just use conditional formatting?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    Jan 2008
    Posts
    75
    Location
    Thanks all, but the problem is that the function call will be part of a menu that when the user clicks will basically highlight the duplicate values in the column name. The function should be reusable so that all I need do is call it using the integer equivalent of the column name. My basic problem is a code that will test if the values are the same or exist in that range and if does it highlights the cell. Right now it is highlighting the entire column being reference in the calling function.

    Thanks, again

    Lucpian

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Function CheckforDuplicateBarcodes(columnname As Integer)
    Dim rowcount
    Dim R
    With Sheet1
    rowcount = .Cells(.Rows.Count, columnname).End(xlUp).Row
    For R = 2 To rowcount
    If Application.CountIf(.Columns(columnname), .Cells(R, columnname).Value) > 1 Then
    .Cells(R, columnname).Interior.ColorIndex = 5
    End If
    Next R
    End With
    End Function

    Sub Duplibutton()
    CheckforDuplicateBarcodes 14
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Regular
    Joined
    Jan 2008
    Posts
    75
    Location

    Smile

    xld, you are awesome. You are a vba guru. Thanks, your code works perfectly.

    -Lucpian

Posting Permissions

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