Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Please help with On Error GoTo

Hello all,

In my code, I inserted an error trapping code in case an error has occurred.
If there is an error, the code will jump to the error handler section and
execute the code in the ErrorHandler section. So the following is what I
have:


On Error Goto ErrorHandler

'The code in between

ErrorHandler:
Msgbox "An error has occurred please contact the IT department",
vbCritical


Somehow, the code from above executes the code in the ErrorHandler: section
even there is no error. The code however did jump right into the
ErrorHandler section when there was an error.

Did I do something wrong? Please help.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Please help with On Error GoTo

One way:

ErrorHandler:

If Err.Number 0 Then
Msgbox "An error has occurred please contact the IT department",
vbCritical
End If

If there is no error is will skip the message box.

"Accesshelp" wrote in message
...
Hello all,

In my code, I inserted an error trapping code in case an error has
occurred.
If there is an error, the code will jump to the error handler section and
execute the code in the ErrorHandler section. So the following is what I
have:


On Error Goto ErrorHandler

'The code in between

ErrorHandler:
Msgbox "An error has occurred please contact the IT department",
vbCritical


Somehow, the code from above executes the code in the ErrorHandler:
section
even there is no error. The code however did jump right into the
ErrorHandler section when there was an error.

Did I do something wrong? Please help.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Please help with On Error GoTo

JLGWhiz,

Thanks for the code. I will try it tomorrow. One thing I do not understand
is I use the same code on one of my macro, and it works perfectly. Now when
I tried to use it on this one, it does not work.

Thanks.

"JLGWhiz" wrote:

One way:

ErrorHandler:

If Err.Number 0 Then
Msgbox "An error has occurred please contact the IT department",
vbCritical
End If

If there is no error is will skip the message box.

"Accesshelp" wrote in message
...
Hello all,

In my code, I inserted an error trapping code in case an error has
occurred.
If there is an error, the code will jump to the error handler section and
execute the code in the ErrorHandler section. So the following is what I
have:


On Error Goto ErrorHandler

'The code in between

ErrorHandler:
Msgbox "An error has occurred please contact the IT department",
vbCritical


Somehow, the code from above executes the code in the ErrorHandler:
section
even there is no error. The code however did jump right into the
ErrorHandler section when there was an error.

Did I do something wrong? Please help.

Thanks.



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Please help with On Error GoTo

Depending on whether your code is a subroutine or function, you can put
either this line of code...

Exit Sub

or this line of code...

Exit Function

immediately in front of your ErrorHandler label line to prevent your regular
code from falling through into your error handling code.

--
Rick (MVP - Excel)


"Accesshelp" wrote in message
...
Hello all,

In my code, I inserted an error trapping code in case an error has
occurred.
If there is an error, the code will jump to the error handler section and
execute the code in the ErrorHandler section. So the following is what I
have:


On Error Goto ErrorHandler

'The code in between

ErrorHandler:
Msgbox "An error has occurred please contact the IT department",
vbCritical


Somehow, the code from above executes the code in the ErrorHandler:
section
even there is no error. The code however did jump right into the
ErrorHandler section when there was an error.

Did I do something wrong? Please help.

Thanks.


Reply
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
Resetting error reporting after On Error GoTo Steve Excel Programming 1 August 14th 09 05:24 AM
On Error Goto 0 Chip Pearson Excel Programming 0 January 6th 07 12:04 AM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
On Error Goto doesn't goto Paul Excel Programming 1 October 15th 04 03:51 PM
On Error Goto doesn't goto Paul Excel Programming 0 October 15th 04 03:05 PM


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

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

About Us

"It's about Microsoft Excel"