Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Well Mike, It took me more than three seconds to figure out what your code wa doing so does my answer qualify ?? :) Firstly, error handlers need some sort of intelligence, so the way write mine are like so: Code ------------------- Dim Found As Boolean '* On Local Error GoTo as_Err ... ... ... as_Res: Worksheets(Sheet_Name).Activate On Local Error GoTo 0 Exit Sub as_Err: Select Case Err.Number Case 9 '* Worksheet not found Call Create_Sheet(Sheet_Name) Resume as_Res Case Else On Local Error GoTo 0 Resume End Select End Sub ------------------- So, the first thing to do is to use a -Local- error handler. If yo don't do this then the error handler adds itself onto the chain o previously declared error handlers and errors rattle up and down th chain causing some difficult bugs in some cases. The second thing to do is to turn your error handler off at the end o the code otherwise any other errors elsewhere will use this erro handler which is something you don't want. Thirdly, give your error handler some intelligence. You don't want i to react the same way for every error. Also give it a way to react t an unexpected error. The 'Case Else' statement above is my 'give up clause. Every handler must be accompanied by a 'resume' statement. Resum statements come in three flavours: - Resume - Resume Next - Resume [Label] Resume Resumes(!!) execution at the statement that caused the error. Resume Next resumes at the statement after the error Resume [label] (Such as the resume as_Res statement above) resumes at particular statement. What you need to do is to place a label (New_tag) like: Code ------------------- New_tag: Message = "Enter the red tag number that was reworked" ' Set prompt. Title = "Red Tag Number" ' Set title. Default = "0" ' Set default. closetag = InputBox(Message, Title, Default) ------------------- Code your error handler as I have shown above and then include th statement Code ------------------- Resume New_tag ------------------- instead of the Code ------------------- Resume Next ------------------- Regards Ric -- Rich_ ----------------------------------------------------------------------- Rich_z's Profile: http://www.excelforum.com/member.php...fo&userid=2473 View this thread: http://www.excelforum.com/showthread.php?threadid=38481 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Error handler | Excel Discussion (Misc queries) | |||
Error Handler | Excel Discussion (Misc queries) | |||
Error Handler Not Working | Excel Discussion (Misc queries) | |||
Error Handler | Excel Programming | |||
Error Handler Not working 2nd time | Excel Programming |