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

Hi,
I posted a post earlier about error management in VBA, but I need a bit more
info on that.

I need My On Error GoTo to point to an If condition that will be activated
only by this error and and want to stop the complete macro, not only the sub.
Actually, I'm using multiple sub.

Thanks!

JJD

--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default On Error GoTo If

Exit Sub before the error handle to ensure the other code doesn't drop into
it, and use End to stop the whole app.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jean-Jerome Doucet via OfficeKB.com" wrote in
message ...
Hi,
I posted a post earlier about error management in VBA, but I need a bit

more
info on that.

I need My On Error GoTo to point to an If condition that will be activated
only by this error and and want to stop the complete macro, not only the

sub.
Actually, I'm using multiple sub.

Thanks!

JJD

--
Message posted via http://www.officekb.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default On Error GoTo If


JJD,
Have your On Error GoTo statement point to a specific line in th
sub where you are trying to trap the error, such as:

On Error GoTo errhndlr

Then at the bottom of your sub put the following

Exit Sub
errhndlr:
' - Then put whatever code you want to run if the error occurs
' - The IF statement in your case
' - IF your condition is true then use END to quit the entire macro

Be sure to have Exit Sub before your error handler so it will not ru
unless an error occurs.
Also make sure your errhndlr: line starts all the way to the left (i
not indented) and that it ends with the colon :

HT

--
bhofset
-----------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...fo&userid=1880
View this thread: http://www.excelforum.com/showthread.php?threadid=38134

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default On Error GoTo If

Put your error handler only in the topmost SUB. Then if there is an error
in a sub called by this sub, it will use the error handler in the topmost
sub


Sub Main()
On Error GoTo ErrHandler
Macro1
Macro2
Macro3

Exit Sub
ErrHandler:
MsgBox "In Error Handler"
End Sub

Sub Macro1()
MsgBox "In Macro1"
End Sub

Sub Macro2()
MsgBox "In Macro2 before Macro4"
Macro4
MsgBox "In Macro2 after Macro4"
End Sub

Sub Macro4()
MsgBox "In Macro4 Before Error"
Err.Raise 5000
MsgBox "In Macro4 After Error"
End Sub

Sub Macro3()
MsgBox "In Macro3"
End Sub


--
Regards,
Tom Ogilvy




"Jean-Jerome Doucet via OfficeKB.com" wrote in
message ...
Hi,
I posted a post earlier about error management in VBA, but I need a bit

more
info on that.

I need My On Error GoTo to point to an If condition that will be activated
only by this error and and want to stop the complete macro, not only the

sub.
Actually, I'm using multiple sub.

Thanks!

JJD

--
Message posted via http://www.officekb.com



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default On Error GoTo If

Ok, I understood that if you put your label at the end of the sub with an
exit sub just before this label, it will only be executed if the error goto
intruction say to go there. The only problem I seem to have is that if I
click cancel or write text in my inputbox, it seems to continue without using
my error handler. Strange.

Werner

Quote:
On Error GoTo IndexError
[...] 'code I just skipped in this quote

Exit Sub 'if no errors exit procedure

IndexError:

MsgBox "Dead end!"
End
Resume

End Sub

--
Message posted via http://www.officekb.com


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default On Error GoTo If

Cancel in an inputbox is not an error. You have to trap that condition and
act accordingly.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jean-Jerome Doucet via OfficeKB.com" wrote in message
...
Ok, I understood that if you put your label at the end of the sub with an
exit sub just before this label, it will only be executed if the error

goto
intruction say to go there. The only problem I seem to have is that if I
click cancel or write text in my inputbox, it seems to continue without

using
my error handler. Strange.

Werner

Quote:
On Error GoTo IndexError
[...] 'code I just skipped in this quote

Exit Sub 'if no errors exit procedure

IndexError:

MsgBox "Dead end!"
End
Resume

End Sub

--
Message posted via http://www.officekb.com



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default On Error GoTo If


What error are you trying to trap?

Put the input box code and what error this is raising in your post

--
bhofset
-----------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...fo&userid=1880
View this thread: http://www.excelforum.com/showthread.php?threadid=38134

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default On Error GoTo If

Thanks for your help Tom Ogilvy! It helped me on my issue.

Regards,

Werner

--
Message posted via http://www.officekb.com
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
On Error Goto ignored Fred Smith Excel Programming 4 January 8th 05 03:49 AM
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
On Error GoTo StanJ[_2_] Excel Programming 1 July 31st 04 06:15 PM
On error goto 0? Brian Tozer Excel Programming 10 December 29th 03 09:59 PM


All times are GMT +1. The time now is 02:40 AM.

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"