Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default If Then using "Find" command

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 ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
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 ***

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default If Then using "Find" command

Hi Jim Thank you very much for the quick reply. I copied and pasted and
I noticed the following is all in red. I get a "compile Error : Syntax
Error" message.

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

Ogopogo5

*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default If Then using "Find" command

the newsgroups wrap text. try this

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

--


Gary

"ogopogo5" wrote in message
...
Hi Jim Thank you very much for the quick reply. I copied and pasted and
I noticed the following is all in red. I get a "compile Error : Syntax
Error" message.

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

Ogopogo5

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default If Then using "Find" command

after you paste it, put the cursor at the end of the first line and press
delete, it should work then.

--


Gary

"Gary Keramidas" <GKeramidasAtMsn.com wrote in message
...
the newsgroups wrap text. try this

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

--


Gary

"ogopogo5" wrote in message
...
Hi Jim Thank you very much for the quick reply. I copied and pasted and
I noticed the following is all in red. I get a "compile Error : Syntax
Error" message.

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

Ogopogo5

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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default If Then using "Find" command

Hi Gary

I got it working, thank you very much for your help.

Ogopogo5

*** Sent via Developersdex http://www.developersdex.com ***
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
How to have a macro simply issue the "find" command or "control f: Charles Adams Excel Programming 3 February 6th 09 06:34 PM
Display message if "find" command comes up blank ?? [email protected] Excel Programming 5 September 27th 07 08:10 PM
Stopping looped "Find" command Varne Excel Discussion (Misc queries) 3 September 24th 07 09:26 AM
How to cancel a find & replace command "midstream"? Matt from GVA Excel Worksheet Functions 4 September 4th 06 05:47 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM


All times are GMT +1. The time now is 04:55 PM.

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

About Us

"It's about Microsoft Excel"