On Error Goto doesn't goto

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wrote a simple script that basically says:

On Error Goto EEERRR
CCC=5
Do a Search/Find for CCC

If the script finds a "5", it's ok. If it doesn't find it, it crashes
instead of going to EEERRR

The error message I get is "Object variable or With block variable not set"

Can someone explain what that message means, and why the On Error Goto
doesn't go?

Thanks!
Paul
 
In the VBE, What do you have checked in tools=>Options under General? Do
you have Break on All Errors checked. If so, that's your huckleberry. You
should have Break on Unhandled errors.

Besides that, it is the select that is causing the error. The better way to
handle a Find is this way:

Sub test2()
Dim rng as Range
On error goto EEERRR

CCC = 2
Range("a10").Select
Set rng = Cells.Find(What:=CCC, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=
_
xlNext, MatchCase:=False)
if not rng is nothing then
rng.Select
else
msgbox CCC & " not found"
End if


EEERRR:
'some code here
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

On Error GoTo stops working 2
On Error Goto 9
On Error GoTo Failing - HELP! 2
On Error GoTo 3
On error GoTo Question 4
Subroutine vs GOTO "On Error" 3
why doesn't on error work? 7
on error goto 2

Back
Top