Is it possible to use the Exit Sub command in an Error Handler?

Status
Not open for further replies.

328mike

New Member
Joined
Jul 5, 2011
Messages
47
Hey all,

When I run my code I get error 20 when I enter a correct answer. I am not sure why it's not working but I assume it is because I have multiple exit sub commands. Any advice here?

Exit Sub
ErrHandler:
Dim AnswerErr As Integer
ErrCount = ErrCount + 1
DataMonth = Application.InputBox _
("Please enter the closest date that resembles " & _
DataMonth & _
", in format (Mm/01/Yyyy)", "Invalid Date Format!")

'Easter Egg
If ErrCount = 4 Then
MsgBox "I've just picked up a fault in the AE35 unit. It's going to go 100% failure in 72 hours Dave. ", vbCritical, "HAL"
DataMonth = Application.InputBox _
("Please enter the closest date that resembles " & _
DataMonth & _
", in format (Mm/01/Yyyy)", "Invalid Date Format!")
If DataMonth = False Then
AnswerErr = MsgBox("Are you sure you don't want to enter a data month? LinkUp Eligibility will not be calculated!", vbYesNo, "Cancel Clicked")
If AnswerErr = 6 Then
DataMonth = ""
Exit Sub
Else
GoTo ErrHandler
End If
Else
GoTo ErrHandler
End If
ElseIf ErrCount = 9 Then
MsgBox "Just what do you think you're doing, Dave? ", vbCritical, "HAL"
DataMonth = Application.InputBox _
("Please enter the closest date that resembles " & _
DataMonth & _
", in format (Mm/01/Yyyy)", "Invalid Date Format!")
If DataMonth = False Then
Answer = MsgBox("Are you sure you don't want to enter a data month? LinkUp Eligibility will not be calculated!", vbYesNo, "Cancel Clicked")
If Answer = 6 Then
DataMonth = ""
Exit Sub
Else
GoTo ErrHandler
End If
Else
On Error GoTo ErrHandler
End If
ElseIf ErrCount = 14 Then
MsgBox "Cake, and grief counseling, will be available at the conclusion of the test. ", vbExclamation, "GLaDOS"
DataMonth = Application.InputBox _
("Please enter the closest date that resembles " & _
DataMonth & _
", in format (Mm/01/Yyyy)", "Invalid Date Format!")
If DataMonth = False Then
Answer = MsgBox("Are you sure you don't want to enter a data month? LinkUp Eligibility will not be calculated!", vbYesNo, "Cancel Clicked")
If Answer = 6 Then
DataMonth = ""
Exit Sub
Else
GoTo ErrHandler
End If
Else
On Error GoTo ErrHandler
End If
ElseIf DataMonth = False Then
Answer = MsgBox("Are you sure you don't want to enter a data month? LinkUp Eligibility will not be calculated!", vbYesNo, "Cancel Clicked")
If Answer = 6 Then
DataMonth = ""
Exit Sub
Else
GoTo ErrHandler
End If
End If
Resume
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Status
Not open for further replies.

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top