ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can I end a sub on error? (https://www.excelbanter.com/excel-programming/395811-can-i-end-sub-error.html)

Aaron

Can I end a sub on error?
 
I need some code so that if the sub errors anywhere the sub simply ends
instead of giving the user the "Debug or End" message box. Please help.

Jim Thomlinson

Can I end a sub on error?
 
You can use On Error Goto something like this...

Sub WhatEver()
On Error GoTo ExitSub
'Your Code

ExitSub:

End Sub
--
HTH...

Jim Thomlinson


"Aaron" wrote:

I need some code so that if the sub errors anywhere the sub simply ends
instead of giving the user the "Debug or End" message box. Please help.


JE McGimpsey

Can I end a sub on error?
 
One way:

Public Sub AbortOnError()
On Error GoTo ErrHandler

'Your code here

Exit Sub
ErrHandler:
'Handle Error, Clean up, or just exit
End Sub

In article ,
Aaron wrote:

I need some code so that if the sub errors anywhere the sub simply ends
instead of giving the user the "Debug or End" message box. Please help.



All times are GMT +1. The time now is 07:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com