title: How to delete duplicate values?
body: <p>I dynamically update the cells in columns A and B, and join both values on each row (using &amp;) and place the values in column C.</p>
  
  <p>My purpose is fulfilled by detecting duplicate names when firstName (Column A values) and LastName (column B values) are entered twice. An empty value (observed when the msgbox is displayed) pops up when I delete the duplicate name followed by the first occurrence.</p>
  
  <p>This is an issue at times, especially because sometimes the msgbox does not go away. ie the code crashes.</p>
  
  <p>How can I prevent the empty value, or msgBox from being displayed? I suspect something is wrong with my if statement.</p>
  
  <p>VBA code I placed in the worksheet </p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Sub Worksheet_Change(ByVal Target As Range)
  
  If WorksheetFunction.CountIf(Range("c1:c12"), Target.Offset(0, 1).Value) &gt; 1 And _
    Target.Offset(0, 1).Value &lt;&gt; " " Then
      MsgBox Target.Offset(0, 1).Value &amp; " is a Duplicate Entry" &amp; vbNewLine &amp; _
      " ENTER A NEW NAME", vbInformation, "Duplicate Detected"
      Target.Offset(0, 0).Value = " "
      Target.Offset(0, 0).Select
  ElseIf WorksheetFunction.CountIf(Range("c1:c12"), Target.Offset(0, 2).Value) &gt; 1 And _
    Target.Offset(0, 1).Value &lt;&gt; " " Then
      MsgBox Target.Offset(0, 2).Value &amp; " is a Duplicate Entry" &amp; vbNewLine &amp; _
      " ENTER A NEW NAME", vbInformation, "Duplicate Detected"
      Target.Offset(0, 0).Value = " "
      Target.Offset(0, 0).Select
  Else: Exit Sub
  End If
  
  End Sub
  </code></pre>