Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Error handler loop?

My code searches for a string, and if found, does something, then continues
in the loop; if not found , it just re-enters the loop (without doing
something). It loops fine through the err handler once, but then it's like
it can't "see" it any more. Is this clear? Is the error handler in the
wrong place, or this just a real goofy to do what I want to do? TIA, guys

My code is:

[...blah, blah]
On Error GoTo Err_Hand91
Cells.Find(What:=Holiday, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
' if no error, must be in holiday cell - call sub
foundHoliday
NextWeek:
X = X + 1
Wend
Err_Hand91:
If Err.Number = 91 Then
Err.Clear
GoTo NextWeek
End If
[blah, blah...]


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Error handler loop?

Hi zSplash,

It's hard to figure out what you're trying to do without seeing all the
code. But I think you may want to use On Error Resume Next, which will
allow execution to continue when an error is encountered. Then you can just
check to see if an error did occur - if so, take appropriate action.

For example:

[...blah, blah]
On Error Resume Next

Cells.Find(What:=Holiday, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
' if no error, must be in holiday cell - call sub
If Err.Number=0 Then foundHoliday
X = X + 1
Wend
[...blah, blah]

--
Regards,

Jake Marx
www.longhead.com


zSplash wrote:
My code searches for a string, and if found, does something, then
continues in the loop; if not found , it just re-enters the loop
(without doing something). It loops fine through the err handler
once, but then it's like it can't "see" it any more. Is this clear?
Is the error handler in the wrong place, or this just a real goofy to
do what I want to do? TIA, guys

My code is:

[...blah, blah]
On Error GoTo Err_Hand91
Cells.Find(What:=Holiday, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _ MatchCase:=False).Activate
' if no error, must be in holiday cell - call sub
foundHoliday
NextWeek:
X = X + 1
Wend
Err_Hand91:
If Err.Number = 91 Then
Err.Clear
GoTo NextWeek
End If
[blah, blah...]


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Error handler loop?

The current error handler is disabled until a Resume, Exit Sub or
Exit Function is reached. You could try:

Resume NextWeek

instead of your GoTo...


OTOH, you could do it without an error handler at all:

Dim found As Range

While...
Set found = Cells.Find(...)
If Not found Is Nothing Then foundHoliday
X = X + 1
Wend


In article ,
"zSplash" <zNOSPAMSplash@ gci.net wrote:

My code searches for a string, and if found, does something, then continues
in the loop; if not found , it just re-enters the loop (without doing
something). It loops fine through the err handler once, but then it's like
it can't "see" it any more. Is this clear? Is the error handler in the
wrong place, or this just a real goofy to do what I want to do? TIA, guys

My code is:

[...blah, blah]
On Error GoTo Err_Hand91
Cells.Find(What:=Holiday, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
' if no error, must be in holiday cell - call sub
foundHoliday
NextWeek:
X = X + 1
Wend
Err_Hand91:
If Err.Number = 91 Then
Err.Clear
GoTo NextWeek
End If
[blah, blah...]


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Error handler loop?

In the Error Handler routine Err_Hand91: try...

Resume NextWeek

instead of

Goto NextWeek.

Without the resume statement, I think the "On Error" statement will not stay
in force, but looking through help did not clarify. "Resume" automatically
clears the error.

Alex



"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
My code searches for a string, and if found, does something, then

continues
in the loop; if not found , it just re-enters the loop (without doing
something). It loops fine through the err handler once, but then it's

like
it can't "see" it any more. Is this clear? Is the error handler in the
wrong place, or this just a real goofy to do what I want to do? TIA, guys

My code is:

[...blah, blah]
On Error GoTo Err_Hand91
Cells.Find(What:=Holiday, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,

_
MatchCase:=False).Activate
' if no error, must be in holiday cell - call sub
foundHoliday
NextWeek:
X = X + 1
Wend
Err_Hand91:
If Err.Number = 91 Then
Err.Clear
GoTo NextWeek
End If
[blah, blah...]




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Error handler loop?

Perfect!! Thanks, guys.

st.

"Alex@JPCS" wrote in message
. ..
In the Error Handler routine Err_Hand91: try...

Resume NextWeek

instead of

Goto NextWeek.

Without the resume statement, I think the "On Error" statement will not

stay
in force, but looking through help did not clarify. "Resume" automatically
clears the error.

Alex



"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
My code searches for a string, and if found, does something, then

continues
in the loop; if not found , it just re-enters the loop (without doing
something). It loops fine through the err handler once, but then it's

like
it can't "see" it any more. Is this clear? Is the error handler in the
wrong place, or this just a real goofy to do what I want to do? TIA,

guys

My code is:

[...blah, blah]
On Error GoTo Err_Hand91
Cells.Find(What:=Holiday, After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows,

SearchDirection:=xlNext,
_
MatchCase:=False).Activate
' if no error, must be in holiday cell - call sub
foundHoliday
NextWeek:
X = X + 1
Wend
Err_Hand91:
If Err.Number = 91 Then
Err.Clear
GoTo NextWeek
End If
[blah, blah...]






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 handler linto Excel Discussion (Misc queries) 1 February 11th 10 12:17 PM
Error Handler Question Jenny B. Excel Discussion (Misc queries) 4 January 9th 08 05:16 PM
Infinite Loop in Error Handler chris Excel Discussion (Misc queries) 2 September 18th 07 02:10 AM
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


All times are GMT +1. The time now is 08:37 PM.

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"