Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Trapping from WSH Tom Chau Excel Discussion (Misc queries) 1 August 25th 06 04:21 AM
error trapping flow23 Excel Discussion (Misc queries) 3 April 13th 06 04:51 PM
Error Trapping Adrian Excel Programming 0 January 31st 05 06:16 PM
Trapping the "Can't find project or library error" Ajtb Excel Programming 1 January 22nd 05 11:16 PM
error trapping libby Excel Programming 5 November 25th 03 10:57 PM


All times are GMT +1. The time now is 01:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"