Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default If this is not found look for something else or error handling

Hi I have this code;

CELLS.find(what:="taf", After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False) _
.Activate

And want to insert either something that says if "taf" is not found
execute the same search but look for sheets("taf").range("k1").value
instead - and then continue doing the rest of the code

However I have tried this without success - so should I just insert
error handling instead (my code is breaking on the cells.find
statement at the moment when it cannot find "taf"). I have never
managed to get my own error handling to work (it seems to execute
whether there is an error or not) so any help on either of these
options would be gratefully recieved.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default If this is not found look for something else or error handling

One way:

Dim rFound As Range
Set rFound = Cells.Find( _
What:="taf", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rFound Is Nothing Then
Set rFound = Cells.Find( _
What:=Sheets("taf").Range("K1").Value, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End If
If rFound Is Nothing Then
MsgBox "Neither 'taf' nor taf!K1 value found"
Else
rFound.Activate
'<rest of your code here
End If

Though I really discourage activating/selecting cells when you can use
the range objects directly.

In article .com,
keri wrote:

Hi I have this code;

CELLS.find(what:="taf", After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False) _
.Activate

And want to insert either something that says if "taf" is not found
execute the same search but look for sheets("taf").range("k1").value
instead - and then continue doing the rest of the code

However I have tried this without success - so should I just insert
error handling instead (my code is breaking on the cells.find
statement at the moment when it cannot find "taf"). I have never
managed to get my own error handling to work (it seems to execute
whether there is an error or not) so any help on either of these
options would be gratefully recieved.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default If this is not found look for something else or error handling

This was excellent, thanks so much for your time & input.

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
Handling nulls found in expression CW Excel Discussion (Misc queries) 1 February 13th 09 04:41 PM
error handling James Cornthwaite Excel Programming 2 June 7th 06 11:06 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
Error handling Tim C Excel Programming 1 October 7th 03 10:00 PM


All times are GMT +1. The time now is 10:08 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"