• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Prevent Adding Duplicate Row based by checking a coloum values

Hello, I have a piece of code to prevent the duplicate data entry in excel worksheet. this code is clearing the content of the cell where the duplicate value is being found but I need to clear the content of this row.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Column = 3 Then
       
        If Evaluate("Countif(c:c," & Target.Address & ")") > 1 Then
            MsgBox Target.Value & " is a duplicate entry.  It will be removed.", vbExclamation, "Data Entry Editor"
            Range(Target.Address).ClearContents
                     
          End If
       
    End If
   
End Sub

Actually i get a file from contextures which suits to my requirement if it can prevent adding the duplicate data by checking the C coloum. file is attached. Please let me know what is the easiest way to achieve this.
 

Attachments

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 Then
        If Evaluate("Countif(c:c," & Target.Address & ")") > 1 Then
            MsgBox Target.Value & " is a duplicate entry.  It will be removed.", vbExclamation, "Data Entry Editor"
            Range(Target.Address).entirerow.ClearContents
          End If
    End If
End Sub

try this..
 
Back
Top