View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default If Then using "Find" command

You need to use a range object to hold the cell found (or not found)

dim rngFound as range

set rngfound = Cells.Find(What:="110", After:=ActiveCell,
LookIn:=xlFormulas, _ LookAt:= xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False , SearchFormat:=False)
If not rngfound is nothing Then
rngfound .select
End If

set rngfound = nothing

set rngfound = Cells.Find(What:="115", After:=ActiveCell,
LookIn:=xlFormulas, _ LookAt:= xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False , SearchFormat:=False)
If not rngfound is nothing Then
rngfound .select
End If
--
HTH...

Jim Thomlinson


"ogopogo5" wrote:

I'm trying to make the following VB work.

If Cells.Find(What:="110", After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate = "" Then
End If

If Cells.Find(What:="115", After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate = "" Then
End If

The first If Then works as there is a "110". However on the second IF
Then there is no "115" and I get a "Run-Time Error 91". Is there a way
to make the second IF Then work, without getting the "Run-Time Error"?

Ogopogo5

*** Sent via Developersdex http://www.developersdex.com ***