title: Avoid multiple error pop up messages in excel
body: <pre><code>Option Explicit
  
  Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
      'Does the validation range still have validation?
      If Not HasValidation(Range(&quot;A1:A1048576&quot;)) Then RestoreValidation
      If Not HasValidation(Range(&quot;C1:C1048576&quot;)) Then RestoreValidation
      If Not HasValidation(Range(&quot;I1:I1048576&quot;)) Then RestoreValidation
      If Not HasValidation(Range(&quot;P1:P1048576&quot;)) Then RestoreValidation
  End Sub
  
  Private Sub RestoreValidation()
      Application.EnableEvents = False
      'turn off events so this routine is not continuously fired
      Application.Undo
      Application.EnableEvents = True
      'and turn them on again so we can catch the change next time
      MsgBox &quot;Your last operation was canceled.&quot; &amp; _
      &quot;It would have deleted data validation rules.&quot;, vbCritical
  End Sub
  
  Private Function HasValidation(r) As Boolean
      '   Returns True if every cell in Range r uses Data Validation
      On Error Resume Next
      Debug.Print r.Validation.Type    'don't care about result, just possible error
      If Err.Number = 0 Then HasValidation = True Else HasValidation = False
  End Function
  </code></pre>
  <p>I applied validation on 4 columns with the above code, Even the validation is passed I am getting 4 error pop up messages how to restrict number of error messages ?</p>
  <p><strong>UPDATE:</strong></p>
  <p>I selected the value from the drop down which is a valid selection, but I am getting the below error message.
  <img src="https://i.stack.imgur.com/jd4v3.png" alt="My sample excel" />I am using the following code</p>