LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default error handler not working correctly


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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error handler linto Excel Discussion (Misc queries) 1 February 11th 10 12:17 PM
Error Handler sharad Excel Discussion (Misc queries) 1 September 17th 07 06:38 PM
Error Handler Not Working Bill Excel Discussion (Misc queries) 0 August 25th 05 07:13 PM
Error Handler dht[_2_] Excel Programming 5 August 19th 04 08:51 AM
Error Handler Not working 2nd time Todd Huttenstine Excel Programming 3 May 18th 04 09:37 PM


All times are GMT +1. The time now is 11:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"