ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trap a find error (https://www.excelbanter.com/excel-programming/318684-trap-find-error.html)

quartz[_2_]

Trap a find error
 
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.

Jim Thomlinson[_3_]

Trap a find error
 
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
"quartz" wrote:

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.


quartz[_2_]

Trap a find error
 
Thanks Jim, works great!

"Jim Thomlinson" wrote:

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
"quartz" wrote:

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.



All times are GMT +1. The time now is 12:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com