Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error Trapping the Find method
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error Trapping the Find method
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 '<<================== --- Regards, Norman "big t" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Error Trapping the Find method
Thanks Norman, that works perfectly!
cheers big t "Norman Jones" wrote: 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 '<<================== --- Regards, Norman "big t" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Error Trapping from WSH | Excel Discussion (Misc queries) | |||
error trapping | Excel Discussion (Misc queries) | |||
Error Trapping | Excel Programming | |||
Trapping the "Can't find project or library error" | Excel Programming | |||
error trapping | Excel Programming |