Find("xx") and @error

DaLiMan

Active Member
Joined
Jun 1, 2004
Messages
295
I'm using the find function like below but when searching for something that does not exist a message comes up with [run-time error '91'].

Now I could use 'on error resume next' but I'm hoping there is another way.

Can anyone help me out?

Code:
iFindA1 = Worksheets(1).UsedRange.Find("xx").Address
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Do you have problme with "on error resume next" ?

Code:
On Error Resume Next
iFindA1 = Worksheets(1).UsedRange.Find("xx").Address
If Err <> 0 Then Exit Sub
On Error GoTo 0
 
Upvote 0
use the following:

Code:
If Not iFindA1 Is Nothing Then
    'normal code here
Else
    'error message here
End If
 
Upvote 0
Hi,

perhaps obvious: did you check the helpfiles ?
there is something like
Code:
Set c = .......FIND ....
you could (and would better do) declare the variable
Code:
Dim c as Range
a range-variable can be Nothing, so there will be no error when trying to "set" c
of course the address of nothing will produce an error
Code:
c.Address
that's why we check it
If Not c Is Nothing Then

kind regards,
Erik
 
Upvote 0
@ erik.van.geit
Yes, I did try the help but did not fully understand what was said.
Now with youre explanation I do....
Thanks. :)

@lozzablake
Accually yes, a little.
When you forget to undo this option you end up with having no error at all.
That's not alway a good thing, especcially for a noob like me..... :oops:

Thanks for the help guys.
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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