View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Kuo[_3_] Sam Kuo[_3_] is offline
external usenet poster
 
Posts: 86
Default Error handler question in Worksheet_Change event

Hi

My code below clears a cell's value then prompts an error message, if the
input value is outside the specified limit.
But I'd prefer to reverse the sequence (i.e. prompts the error message
first, then clear the input upon accpeting the error message) but don't know
how...

Any help is appreciated.

Sam


Private Sub Worksheet_Change(ByVal Target As Range)

Dim MyWkSht As Worksheet
Dim ARIRange As Range

Set MyWkSht = ThisWorkbook.Worksheets("Sheet1")
Set ARIRange = MyWkSht.Range("N13")

MyWkSht.Unprotect (1)

' Other codes

If ARIRange.Value < 50 Or ARIRange.Value 130 Then
ARIRange.Value = ""
MyWkSht.Protect (1)
GoTo ErrorHandler
Exit Sub

ErrorHandler:
MsgBox "Please enter a value between 50mm and 130mm.", vbOKOnly,
"Warning"
End

Else
End If

MyWkSht.Protect (1)

End Sub