Uses a Resume statement after an error occurs: : Resume « Language Basics « VBA / Excel / Access / Word






Uses a Resume statement after an error occurs:

 
Sub EnterSquareRoot6()
    Dim Num As Variant
    Dim Msg As String
    Dim Ans As Integer
TryAgain:
    On Error GoTo BadEntry
    Num = InputBox("Enter a value")
    If Num = "" Then Exit Sub
    ActiveCell.value = Sqr(Num)
    Exit Sub
BadEntry:
    Msg = "An error occurred. Try again?"
    Ans = MsgBox(Msg, vbYesNo)
    If Ans = vbYes Then Resume TryAgain
End Sub

 








Related examples in the same category

1.using the On Error Resume Next statement
2.Check the error number with Select Case statement