Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Using Selection.Find in a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Erik K - 15 Oct 2005 09:47 GMT
I have set a selection find in a macro to find the word "Alternate" and
replace it with a name.  The problem is that if it does not find the word
"Alternate" the macro doesn't run.  Help!
Tony Jollans - 15 Oct 2005 11:22 GMT
Would  you care to try again - and perhaps post some code?

If the macro doesn't run, it neither finds nor not finds anything and,
anyway, what do you want it to do when it doesn't find your string -
obviously it can't replace something it can't find.

--
Enjoy,
Tony

> I have set a selection find in a macro to find the word "Alternate" and
> replace it with a name.  The problem is that if it does not find the word
[quoted text clipped - 3 lines]
> Message posted via OfficeKB.com
> http://www.officekb.com/Uwe/Forums.aspx/word-programming/200510/1
Erik K - 15 Oct 2005 11:57 GMT
How is this?:

   Range("V38,V45,V52,V58,V65,V72,V78,V84").Select
       If Range("AG21").Value = "N" And ActiveCell <> "Tony" Then
       Selection.Find(What:="Alternate", After:=ActiveCell, LookIn:
=xlFormulas,
       LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
       MatchCase:=False, SearchFormat:=False).Activate
       ActiveCell.FormulaR1C1 = "Tony"
       ElseIf Range("AG24").Value = "N" And ActiveCell <> "Robert" Then
       Range("V12,V17,V24,V28,V34,V38,V44,V50,V57,V63,V69,V74,V79,V85").
Select
       Selection.Find(What:="Alternate", After:=ActiveCell, LookIn:
=xlFormulas, _
       LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
       MatchCase:=False, SearchFormat:=False).Activate
       ActiveCell.FormulaR1C1 = "Robert"
       End If

>Would  you care to try again - and perhaps post some code?
>
[quoted text clipped - 9 lines]
>> replace it with a name.  The problem is that if it does not find the word
>> "Alternate" the macro doesn't run.  Help!
Tony Jollans - 15 Oct 2005 13:46 GMT
This is an Excel problem and would be better asked in an Excel group.

In brief, you cannot Activate a cell which hasn't been found and you need to
do something like ..

Set TempRange = Selection.Find(etc...=False)
If not TempRange is nothing then Temprange.Activate

--
Enjoy,
Tony

> How is this?:
>
[quoted text clipped - 32 lines]
> Message posted via OfficeKB.com
> http://www.officekb.com/Uwe/Forums.aspx/word-programming/200510/1
Erik K - 15 Oct 2005 12:00 GMT
What I want with this is to find any cell that has "Alternate" in it and
replace it with Tony.  If there are not any "Alternate" cells, then I want to
continue on with the next part of my macro.

>Would  you care to try again - and perhaps post some code?
>
[quoted text clipped - 9 lines]
>> replace it with a name.  The problem is that if it does not find the word
>> "Alternate" the macro doesn't run.  Help!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.