Selection.Find issue

Nos

New Member
Joined
Feb 25, 2006
Messages
20
Hi guys, I was hoping someone could give me some advice.

I'm running a Find through a specific selection. It works perfectly except for when the value it is searching for is not present in the selection. I tried to use the On Error command but the run time error box still comes up? Is there another way I can divert the macro if the value I am searching for is not found in the selection? (I need to take into account that sometimes the macro will search for values that are not in the selection.



Thanks for your help

Code:
Selection.Find(What:=OfficeRecNo, After:=ActiveCell, LookIn:=xlValues, LookAt _
        :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase _
        :=False, SearchFormat:=False).Activate
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Derek

Well-known Member
Joined
Feb 16, 2002
Messages
1,592
Hi there

EDITTED:

Try this:

On Error GoTo OUT
Selection.Find(What:="OfficeRecNo", After:=ActiveCell, LookIn:=xlFormulas _
, LookAt:=xlwhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False).Activate
OUT:
End Sub

regards
Derek
 

Nos

New Member
Joined
Feb 25, 2006
Messages
20
Unfortunatly that doesn't seem to be working, I'm getting

Code:
Run time error '91'
Object variable or with block variable not set

Thanks for the help though
 

agihcam

Well-known Member
Joined
Jan 16, 2006
Messages
1,624
how about?
Code:
With Selection
Set c = .Find(OfficeRecNo, , , xlWhole)
If Not c Is Nothing Then
c.Select
End If
End With
 

Nos

New Member
Joined
Feb 25, 2006
Messages
20
Thanks so much, that seems to have solved the problem.
 

Forum statistics

Threads
1,136,260
Messages
5,674,697
Members
419,520
Latest member
Jennifer4Dillon

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
Top