Display Error Message and Stop VBA Process when Text Not Found

Godlewskij

New Member
Joined
Jul 26, 2010
Messages
2
I've got an Excel tool I built to analyze reports. The tool works fine, but after it finishes deleting the info I'm not interested in, it occasionally ends up with no findings. This is good, but confusing to some others who may need to use my tool. What I would like to do is enter new VBA Code at a certain point that will search for the text "XYZ" in column A. If "XYZ" is found, then continue processing. However, if "XYZ" is not found, I want a message displayed "There are no XYZ's found in the report" and then have the VBA process stop at that point.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try

Code:
Dim Found As Range
Set Found = Columns("A").Find(what:="XYZ", LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
    MsgBox "XYZ not found", vbExclamation
    Exit Sub
End If
 
Upvote 0
VoG, Thanks. Worked like a charm. This is why I love the MrExcel website. Been using it for years and the two times I haven't been able to figure something out, someone if the forum has been able to help.

Thanks Again. Joe
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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