How to deal with Find when nothing is found

G

Guest

I have this in my Sub.

Cells.Find(what:=LOC, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate

If the string is not found, it runs an error, giving the user the option to
debug. How can I have it comeback and say the string was not found and then
end the sub? Am I making sense? Thanks.
 
G

Guest

hi
dim findnotfind as range
set findnotfind = Cells.Find(what:=LOC, After:=ActiveCell, LookIn:=xlValues,
LookAt:=xlPart,
SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
if findnotfind is nothing then
msgbox "I'm sorry the value was not found"
exit sub
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top