![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 06:58 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com