Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Handling nulls found in expression | Excel Discussion (Misc queries) | |||
error handling | Excel Programming | |||
Error Handling - On Error GoTo doesn't trap error successfully | Excel Programming | |||
Error handling with a handling routine | Excel Programming | |||
Error handling | Excel Programming |