Handle Error Code 91 and Move on to Next Operation

tidalwavedc9

New Member
Joined
Sep 2, 2014
Messages
2
Hello,

Help with this would be much appreciated. I wrote a program that seeks out a specific string and modifies the format of it's cell once it is found. Sometimes the string will exist on the sheet and sometimes it won't. I need the program to keep running and do its job if the string isn't found...instead it keeps crashing. I though the code below would handle the error:

Columns("B:B").Select

Selection.Find(What:="String", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate

If Err.Number = 91 Then
End
Else
"Block of code that modifies cell"
End If

What can I do to tell it to ignore the error and move on?

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Assign the result to a Range variable and test if it's Nothing:

Code:
Dim rngFound as Range
Set rngFound = Columns("B:B").Find(What:="String", LookIn:=xlFormulas, LookAt:=xlPart, _
                       SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If not rngFound is Nothing then
   rngFound.Activate
"Block of code that modifies cell"
End If
 
Upvote 0
Thanks Rory,


I applied the methodology you showed me to all the code blocks that hunt specific strings and it works perfectly.



Much Appreciated,
Mike
 
Upvote 0
Glad to help. Welcome to the forum, by the way. :)
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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