PC Review


Reply
Thread Tools Rate Thread

Another Error Handling Question

 
 
brichard429
Guest
Posts: n/a
 
      26th Nov 2009
I have a sub routine that may generate an error if a value is not defined.
While developing the code I've come accross the error and get an error
statement. I have to reset the code by selecting the reset button in the VBA
window to get it to work again. It's not a code issue but a data issue. I'm
not looking for a way to correct the data but I would like to use an error
handler to simply display a message and return the control back to the
spreadsheet so that the routine can run again without having to go to the
Debug window and resetting the code. Any suggestion?

Thank You,
--
Bernie
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      26th Nov 2009
what do you mean by "not defined"? you can check issues and trap them in
your code. The fact that you get the debug window suggests that all you need
is to add a few
ON ERROR GOTO errorline
traps




"brichard429" <(E-Mail Removed)> wrote in message
news:4B9FF360-08F3-49E3-B62C-(E-Mail Removed)...
> I have a sub routine that may generate an error if a value is not defined.
> While developing the code I've come accross the error and get an error
> statement. I have to reset the code by selecting the reset button in the
> VBA
> window to get it to work again. It's not a code issue but a data issue.
> I'm
> not looking for a way to correct the data but I would like to use an error
> handler to simply display a message and return the control back to the
> spreadsheet so that the routine can run again without having to go to the
> Debug window and resetting the code. Any suggestion?
>
> Thank You,
> --
> Bernie


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      26th Nov 2009
Put this line at the beginning of the problem code segment:

On Error GoTo ErrHandler:

Then put this code near the end of the macro.

ErrHandler:
MsgBox "Error Number " & Err.Number & " Has Occurred. Restart Macro"
Err.Clear

This gives you the error number which you can evaluate before restarting.



"brichard429" <(E-Mail Removed)> wrote in message
news:4B9FF360-08F3-49E3-B62C-(E-Mail Removed)...
>I have a sub routine that may generate an error if a value is not defined.
> While developing the code I've come accross the error and get an error
> statement. I have to reset the code by selecting the reset button in the
> VBA
> window to get it to work again. It's not a code issue but a data issue.
> I'm
> not looking for a way to correct the data but I would like to use an error
> handler to simply display a message and return the control back to the
> spreadsheet so that the routine can run again without having to go to the
> Debug window and resetting the code. Any suggestion?
>
> Thank You,
> --
> Bernie



 
Reply With Quote
 
brichard429
Guest
Posts: n/a
 
      27th Nov 2009
Thank You, This is what I was looking for.
--
Bernie


"JLGWhiz" wrote:

> Put this line at the beginning of the problem code segment:
>
> On Error GoTo ErrHandler:
>
> Then put this code near the end of the macro.
>
> ErrHandler:
> MsgBox "Error Number " & Err.Number & " Has Occurred. Restart Macro"
> Err.Clear
>
> This gives you the error number which you can evaluate before restarting.
>
>
>
> "brichard429" <(E-Mail Removed)> wrote in message
> news:4B9FF360-08F3-49E3-B62C-(E-Mail Removed)...
> >I have a sub routine that may generate an error if a value is not defined.
> > While developing the code I've come accross the error and get an error
> > statement. I have to reset the code by selecting the reset button in the
> > VBA
> > window to get it to work again. It's not a code issue but a data issue.
> > I'm
> > not looking for a way to correct the data but I would like to use an error
> > handler to simply display a message and return the control back to the
> > spreadsheet so that the routine can run again without having to go to the
> > Debug window and resetting the code. Any suggestion?
> >
> > Thank You,
> > --
> > Bernie

>
>
> .
>

 
Reply With Quote
 
brichard429
Guest
Posts: n/a
 
      27th Nov 2009
Thank you Patrick for the reply. The error is a result of a "find" procedure
that has no results and therefore gives the "not defined" value. I wasn't
sure how to handle the particular error so I wanted to use the error check to
provide a message to the user and continue execution.
--
Bernie


"Patrick Molloy" wrote:

> what do you mean by "not defined"? you can check issues and trap them in
> your code. The fact that you get the debug window suggests that all you need
> is to add a few
> ON ERROR GOTO errorline
> traps
>
>
>
>
> "brichard429" <(E-Mail Removed)> wrote in message
> news:4B9FF360-08F3-49E3-B62C-(E-Mail Removed)...
> > I have a sub routine that may generate an error if a value is not defined.
> > While developing the code I've come accross the error and get an error
> > statement. I have to reset the code by selecting the reset button in the
> > VBA
> > window to get it to work again. It's not a code issue but a data issue.
> > I'm
> > not looking for a way to correct the data but I would like to use an error
> > handler to simply display a message and return the control back to the
> > spreadsheet so that the routine can run again without having to go to the
> > Debug window and resetting the code. Any suggestion?
> >
> > Thank You,
> > --
> > Bernie

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
error handling question ADK Microsoft Excel Programming 13 17th Jul 2007 04:00 PM
Error Handling question =?Utf-8?B?SkBZ?= Microsoft Excel Programming 3 22nd Jun 2007 06:16 PM
Another Question on Error Handling Tom Jastrzebski Microsoft ASP .NET 0 12th Feb 2006 01:20 AM
Error Handling Question =?Utf-8?B?UmFlZCBTYXdhbGhh?= Microsoft ASP .NET 1 31st Mar 2005 01:43 PM
Question about best practices with SqlConnection, error handling and memory handling Lars-Erik Aabech Microsoft ADO .NET 9 17th Apr 2004 06:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:17 AM.