Error Trapping the Find method

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

Guest

Hi everyone,

I'm using the Find method in VBA to return the row containing specific text.
Trouble is if the text isn't in the column I'm searching I just get a VBA
error.

I've tried using :

If IsError(<Find syntax>) Then...

but that doesn't seem to work.

Anyone have any ideas about error trapping this thing? At the moment I'm
using On Error Resume Next, but I don't really want to!

TIA
big t
 
Hi Big T,

Try something like:
'===================>>
Sub aTester01()
Dim RngFound As Range
Const SearchStr As String = "ABC"

Set RngFound = Cells.Find(SearchStr, LookIn:=xlValues)

If Not RngFound Is Nothing Then
'Found! So do something, e.g.:
MsgBox SearchStr & " found at " & RngFound.Address(0, 0)
Else
MsgBox SearchStr & " not found!"
End If

End Sub
'<<==================
 

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