Trap a find error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code. How can I most efficiently exit the function if no
target string is found?

strSearchColumn = "I:I"
strTarget = "0"
Set rngFind = Range(strSearchColumn).Find(strTarget,
SearchDirection:=xlPrevious)
strLastDeleteRow = rngFind.Row

Thanks in advance.
 
strSearchColumn = "I:I"
strTarget = "0"
Set rngFind = Range(strSearchColumn).Find(strTarget,
SearchDirection:=xlPrevious)
If rngFind Is Nothing Then
MsgBox "Not Found"
Else
strLastDeleteRow = rngFind.Row
End If

HTH
 
Thanks Jim, works great!

Jim Thomlinson said:
strSearchColumn = "I:I"
strTarget = "0"
Set rngFind = Range(strSearchColumn).Find(strTarget,
SearchDirection:=xlPrevious)
If rngFind Is Nothing Then
MsgBox "Not Found"
Else
strLastDeleteRow = rngFind.Row
End If

HTH
 

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

Back
Top