handling an error

Lino

Active Member
Joined
Feb 27, 2002
Messages
429
Hello

i have the following code...how can i set this up that if it doesn't find what it is looking for then not to throw a runtime error?

Selection.Find(What:="9/11/01", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Select

thanks,

lino
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
On Error Resume Next
Selection.Find(What:="9/11/01", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Select
On Error Goto 0

But, depending what else goes on, an untagged failure here may cause unexpected results, or fatal error, later...
 
Upvote 0
What do you actually want the code to do?

Can you post the rest of it?

You could try something like this:

Code:
Dim rng As Range

Set rng = Selection.Find(What:="9/11/01", After:=ActiveCell, LookIn:=xlValues, _ 
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
MatchCase:=False)

If Not (rng Is Nothing) Then
     rng.Select
End If

BTW you don't necessarily need to Select/Activate ranges to work with them.
 
Upvote 0

Forum statistics

Threads
1,206,826
Messages
6,075,083
Members
446,118
Latest member
Alqahtanir

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