Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default My errorical understanding of Error handling

Hi,

I have probably asked this before, but havent been able to understand
properly.

Please explain how to write code which explains error handling. I have seen

a) on Error goto 0

What does 0 mean. Is it an ID?

b) And sometimes

on error goto Abortret
-
-
-
-

and near the end of the sub we have

Abortnet:
msgbox MsgBox Err.Description
end sub

Suppose in b) we encounter an error, then after displaying the msgbox and
the user pressing ok,does the sub stop executing (or rather finishes
executing as the statement after Msgbox is End Sub) My doubt is does the
control in error handling move to end sub as the line after msgbox is end
sub?

Please give me some explanations/links about error handling as I need to use
it for some unpredicted circumstance like finding for a particular string in
a cell and what if it is not found (I would like to continue with running of
the sub just after find statement).

Please guide me.

Thanks a lot,
Hari
India


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default My errorical understanding of Error handling

VBA executes sequetially. when you use goto you move sequential processing
to a new line. It then continues to execute sequentially until it
terminates or is directed to a different location. So, after the goto, it
displays the message and executes End Sub.

Documented pretty well in VBA help. Put Resume in a module, highlight it
and hit F1.

I get 2 choice:

On Error Statement

Resume Statement



Review both.



That said, FIND does NOT raise an error. Appending an activate or trying to
use a property of the range found raises an error when Find was not
successful. This is a design issue easily avoided.



set rng = Cells.Find("SomeString")

if not rng is nothing then

'process the found cell

rng.Select ' if you must

End if

rather than

Cells.Find("SomeString").Activate



which raises an error when FIND returns NOTHING

Also, best to specify the argument list to find as many of the settings are
persistent and can cause unpredictable behavior if you don't include them
specificially. (for example lookin:=xlformulas ,lookat:=xlWhole)



expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection,
MatchCase)

--

Regards,

Tom Ogilvy



"Hari Prasadh" wrote in message
...
Hi,

I have probably asked this before, but havent been able to understand
properly.

Please explain how to write code which explains error handling. I have

seen

a) on Error goto 0

What does 0 mean. Is it an ID?

b) And sometimes

on error goto Abortret
-
-
-
-

and near the end of the sub we have

Abortnet:
msgbox MsgBox Err.Description
end sub

Suppose in b) we encounter an error, then after displaying the msgbox and
the user pressing ok,does the sub stop executing (or rather finishes
executing as the statement after Msgbox is End Sub) My doubt is does the
control in error handling move to end sub as the line after msgbox is end
sub?

Please give me some explanations/links about error handling as I need to

use
it for some unpredicted circumstance like finding for a particular string

in
a cell and what if it is not found (I would like to continue with running

of
the sub just after find statement).

Please guide me.

Thanks a lot,
Hari
India




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 268
Default My errorical understanding of Error handling

Hi

This is a complex subject, and not just a few lines! On error goto 0 is
used to bypass error traps, and on error goto abortnet, is used to redirect
macro execution to a specific address (abortnet), where the error is handled,
e.g. with a message box, after which the routine sometimes end. There are
also commands like Resume and Resume Next, which is also often used in error
trapping, to clear a trap already encountered. The best would be to get a
good book on the subject!

"Hari Prasadh" wrote:

Hi,

I have probably asked this before, but havent been able to understand
properly.

Please explain how to write code which explains error handling. I have seen

a) on Error goto 0

What does 0 mean. Is it an ID?

b) And sometimes

on error goto Abortret
-
-
-
-

and near the end of the sub we have

Abortnet:
msgbox MsgBox Err.Description
end sub

Suppose in b) we encounter an error, then after displaying the msgbox and
the user pressing ok,does the sub stop executing (or rather finishes
executing as the statement after Msgbox is End Sub) My doubt is does the
control in error handling move to end sub as the line after msgbox is end
sub?

Please give me some explanations/links about error handling as I need to use
it for some unpredicted circumstance like finding for a particular string in
a cell and what if it is not found (I would like to continue with running of
the sub just after find statement).

Please guide me.

Thanks a lot,
Hari
India



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
Error Handling Kevin Excel Discussion (Misc queries) 4 June 19th 08 12:31 AM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
error handling off?? Tom Ogilvy Excel Programming 0 August 19th 04 04:31 PM
Error Handling James Agostinho Excel Programming 1 January 30th 04 06:40 AM
Type Mismatch Error help understanding Ray Batig Excel Programming 5 January 3rd 04 03:07 AM


All times are GMT +1. The time now is 04:37 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"