LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Help with find and replace routine

I need to be able to search for some text and replace it. After recording a
macro and editing it I have this

1 Found_name = _
2 Cells.Find(What:="actualAxis2", After:=ActiveCell, LookIn:=xlFormulas, _
3 LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
4 MatchCase:=False).Activate

5 If Found_name = True Then
6 ActiveCell.Replace What:="actualAxis2", Replacement:="EL",
LookAt:=xlPart _
7 , SearchOrder:=xlByRows, MatchCase:=False
8 End If

Lines 2,3,4,6,7 were extracted from the macro I recorded. If the string is
not found, the macro blows up. I added lines 1,5, and 8 to handle the
condition where the find fails. This is not exactly what I had while
working this at work but it should be sufficient to form the question.

How do I write the If statement to bypass the replace statement when the
find is not sucessful?
If you happen to eliminate any items from these statements that are not
needed, that would be cool.

My followup question is:
How can I write a subroutine to the effect:

call replacement( old_text, new_text )

Such that I don't need to copy that code over and over to replace a series
of strings.
I could then write

replacement( "actualAzis1, AZ)
replacement( "actualAzis2, EL)
replacement( "actualAzis3, X)
replacement( "actualAzis4, Y)

and all four replacements would be made. If one string was not found, the
other three replacements would have been completed without error.
--
Thank you,
Bryan Kelly
Time is the medium we use to express out priorities.


 
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
Find and Replace - Replace with Blank Space Studebaker Excel Discussion (Misc queries) 4 April 3rd 23 10:55 AM
Routine to find exact Row matches in Col1 Col2 Col3 but exact offsetting numbers in Col4 [email protected] Excel Discussion (Misc queries) 0 June 11th 08 11:30 PM
where to put results of find operation in find and replace functio DEP Excel Worksheet Functions 5 November 15th 06 07:52 PM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
Help needed with FIND routine. Matthew[_8_] Excel Programming 4 October 5th 03 11:50 PM


All times are GMT +1. The time now is 08:39 AM.

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"