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
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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
 

lozzablake

Well-known Member
Joined
Dec 15, 2005
Messages
818
use the following:

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

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

DaLiMan

Active Member
Joined
Jun 1, 2004
Messages
295
@ 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.
 

Watch MrExcel Video

Forum statistics

Threads
1,113,811
Messages
5,544,448
Members
410,611
Latest member
JB_101920
Top