macro search error stopped macro run

  • Thread starter Thread starter mel.krom
  • Start date Start date
M

mel.krom

This appears to great great for repeat searches on for the
boardVT value, but fails and stops the macro with run-time
error 91 when no match is found. How can I correct or
handle error.

Range("K" & foundRAL, "K" & foundRAH).Select
Dim asisfind
BoardlocVT = Trim(BoardlocV) & ","
asisfind = Selection.Find(What:=BoardlocVT,
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

Thanks
 
Mel,

Try:

Range("K" & foundRAL, "K" & foundRAH).Select
Dim asisfind As Range
BoardlocVT = Trim(BoardlocV) & ","
Set asisfind = Selection.Find(What:=BoardlocVT,
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not asisfind is Nothing Then
'What to do when it is found
Else
'What to do when it isn't found
End If
 
Mel

See inline additions for one method........

This appears to great great for repeat searches on for the
boardVT value, but fails and stops the macro with run-time
error 91 when no match is found. How can I correct or
handle error.

Range("K" & foundRAL, "K" & foundRAH).Select
Dim asisfind

On Error GoTo mess
BoardlocVT = Trim(BoardlocV) & ","
asisfind = Selection.Find(What:=BoardlocVT,
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

mess:
MsgBox "Nothing Found"


Gord Dibben Excel MVP
 
Back
Top