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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
 
Upvote 0
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
 
Upvote 0
how about?
Code:
With Selection
Set c = .Find(OfficeRecNo, , , xlWhole)
If Not c Is Nothing Then
c.Select
End If
End With
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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