close

I am using a Range(XX).Find search to find a name in a single column,
and I am trying to build an error handling routine so that different
actions will execute depending on whether the query is found. The
trouble is that the error routine executes every time regardless of the
result of the search.

Here is the code:

Sub Look_Here1()
Dim FoundCell As Range
Dim WhatFor As Variant
WhatFor = ActiveSheet.Cells(7, 2).Value

Set FoundCell = Range(quot;B8:B990quot;).Find(What:=WhatFor,
after:=ActiveCell, _
SearchDirection:=xlNext, searchorder:=xlByRows,
_
MatchCase:=False)

FoundCell.Offset(0, -1).Select
ActiveCell.FormulaR1C1 = quot;Xquot;
Selection.Offset(0, 3).Select

On Error GoTo NotFound

NotFound:
Range(quot;a7quot;).Select
ActiveCell.FormulaR1C1 = quot;Xquot;
Range(quot;D7quot;).SelectEnd Sub

Where have I gone wrong?

Any help will be appreciated.
mbIf FoundCell is Nothing then
...
else
...
end if

HTH
--
AP

quot;michaelberrierquot; gt; a écrit dans le message de news:
...
gt;I am using a Range(XX).Find search to find a name in a single column,
gt; and I am trying to build an error handling routine so that different
gt; actions will execute depending on whether the query is found. The
gt; trouble is that the error routine executes every time regardless of the
gt; result of the search.
gt;
gt; Here is the code:
gt;
gt; Sub Look_Here1()
gt; Dim FoundCell As Range
gt; Dim WhatFor As Variant
gt; WhatFor = ActiveSheet.Cells(7, 2).Value
gt;
gt; Set FoundCell = Range(quot;B8:B990quot;).Find(What:=WhatFor,
gt; after:=ActiveCell, _
gt; SearchDirection:=xlNext, searchorder:=xlByRows,
gt; _
gt; MatchCase:=False)
gt;
gt; FoundCell.Offset(0, -1).Select
gt; ActiveCell.FormulaR1C1 = quot;Xquot;
gt; Selection.Offset(0, 3).Select
gt;
gt; On Error GoTo NotFound
gt;
gt; NotFound:
gt; Range(quot;a7quot;).Select
gt; ActiveCell.FormulaR1C1 = quot;Xquot;
gt; Range(quot;D7quot;).Select
gt;
gt;
gt; End Sub
gt;
gt; Where have I gone wrong?
gt;
gt; Any help will be appreciated.
gt; mb
gt;
Works perfect. I bet I tried every word in that space except
quot;nothingquot;.

Thanks a bunch.
mb

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()