On Error code in VBA

lizardtoe

Board Regular
Joined
Jun 20, 2002
Messages
128
I have two 'Cells.Find()' funtions in my macro before each of the functions I have an
'On Error GoTo ' statement. they each go to a different line number

for some reason, if there is an error in the first Cells.Find () [the search value is not there] then the macro will not recognize the second On Error GoTo and it just gives me a run-time error

is this normal? how can I get around it?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
to clarify, it only gives a run-time error in the second one if the search value is not there.

let me know if you need more details, or want to see code
 
Upvote 0
This might help... from the help text:

Error-handling routines rely on the value in the Number property of the Err object to determine the cause of the error. The error-handling routine should test or save relevant property values in the Err object before any other error can occur or before a procedure that might cause an error is called. The property values in the Err object reflect only the most recent error. The error message associated with Err.Number is contained in Err.Description.

Also:

Note that Err.Clear is used to clear the Err object's properties after the error is handled.

'Check for likely Automation errors.
If Err.Number = 440 Or Err.Number = 432 Then
' Tell user what happened. Then clear the Err object.
Msg = "There was an error attempting to open the Automation object!"
MsgBox Msg, , "Deferred Error Test"
Err.Clear ' Clear Err object fields
End If
 
Upvote 0
I tried the Err.Clear and that did not help.

it is a Run-Time error '91'
Object variable or With block variable not set.
 
Upvote 0
Is the problem that the Cells.Find() function works (but is not the info you wanted), then the Cells.FindNext() fails?
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,194
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top