How to deal with Find when nothing is found

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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
 
Back
Top