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...]
Jake Marx - 09 Oct 2003 23:56 GMT
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]

Signature
Regards,
Jake Marx
www.longhead.com
> 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
[quoted text clipped - 21 lines]
> End If
> [blah, blah...]
J.E. McGimpsey - 10 Oct 2003 00:00 GMT
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
> 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
[quoted text clipped - 20 lines]
> End If
> [blah, blah...]
Alex@JPCS - 10 Oct 2003 00:05 GMT
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
> 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
[quoted text clipped - 20 lines]
> End If
> [blah, blah...]
zSplash - 10 Oct 2003 23:00 GMT
Perfect!! Thanks, guys.
st.
> In the Error Handler routine Err_Hand91: try...
>
[quoted text clipped - 37 lines]
> > End If
> > [blah, blah...]
Davini993 - 31 Mar 2006 15:00 GMT
Jajsus H - I've been going mental trying to work out what was going wrong.
But all ok now thanks to this!