Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Using FIND in Visual Basic

I am trying to use the Selection.Find in a macro, and want to know how to get
past the part when it cannot find a cell matching the criteria. It works fine
when it can find something, but when it does not find it, I get a Run-time
error 91 (Object variable or With Block variable not set). Does it have
something to do with the Activate part of my code? I am using the following:

Selection.Find(What:="20?-", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

In other words, is there a way to ask it to find, but without activating? I
want it to do something else if it cannot find a cell matching the criteria.
Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Using FIND in Visual Basic

Use a range object something like this...

dim rngFound as range

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

if rngfound is nothing then
msgbox "Not Found"
else
...

end if
--
HTH...

Jim Thomlinson


"Mike" wrote:

I am trying to use the Selection.Find in a macro, and want to know how to get
past the part when it cannot find a cell matching the criteria. It works fine
when it can find something, but when it does not find it, I get a Run-time
error 91 (Object variable or With Block variable not set). Does it have
something to do with the Activate part of my code? I am using the following:

Selection.Find(What:="20?-", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

In other words, is there a way to ask it to find, but without activating? I
want it to do something else if it cannot find a cell matching the criteria.
Thanks in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Using FIND in Visual Basic

thanks. I'll give that a shot.

"Jim Thomlinson" wrote:

Use a range object something like this...

dim rngFound as range

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

if rngfound is nothing then
msgbox "Not Found"
else
...

end if
--
HTH...

Jim Thomlinson


"Mike" wrote:

I am trying to use the Selection.Find in a macro, and want to know how to get
past the part when it cannot find a cell matching the criteria. It works fine
when it can find something, but when it does not find it, I get a Run-time
error 91 (Object variable or With Block variable not set). Does it have
something to do with the Activate part of my code? I am using the following:

Selection.Find(What:="20?-", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate

In other words, is there a way to ask it to find, but without activating? I
want it to do something else if it cannot find a cell matching the criteria.
Thanks in advance.

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 do you use visual basic to find cross product of two vectors TESHA WHYTE Excel Worksheet Functions 2 November 6th 08 05:50 AM
visual basic. find copy row past into new sheet Chuck Excel Worksheet Functions 3 December 17th 07 09:02 PM
Where do I find help for Visual Basic for Applications Extensibili Lee Hunter Excel Programming 2 October 19th 05 05:39 PM
Using Find/Replace in Visual basic to adapt the code Zakynthos Excel Programming 6 September 8th 05 03:41 PM
Visual Basic code to find next available (blank) row in a spreadsh TB Excel Programming 2 July 15th 05 08:01 PM


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

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"