LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Find&Replace text in Comments

How would this work within a macro where I want to replace the following
ActiveCell.FormulaR1C1 = "1/1/2004" all the first character with "2" and
so on. I am trying to replace 1 to 2 from January to February and do this
with all the months.

"Rafael Guerreiro Osorio" wrote:

If you mean that you have to find and replace more than one ocurrence of OLD,
its just a matter of making the function recursive, finding the first OLD,
then the second and so forth.

Comment doesn't have a Replace or Find Method. If you want to use START and
OVERWRITE of the Text method, default is overwrite, it will substitute
everything after START with TEXT; with overwrite set to false, it will insert
TEXT at START.

I used the Sub Sample below to find and change the text in a comment using
SubsTxt without any problem.

Sub Sample()
strNew = SubsTxt(Range("A1").Comment.Text, "OLD", "NEW")
Range("A1").Comment.Text strNew
End Sub

"John Svendsen" wrote:

Hi Rafael,

Thank you so much for replying - truly, I had not thought of doing a
repleace this way - ingenious.

However, my problem is how to access (find & replace) text in Comments
Object, which are in individual cells

Rgds, JS

"Rafael Guerreiro Osorio"
wrote in message ...
Hi John,

Try a different approach using string functions. You might find the sample
code below useful:

Sub Sample()
MsgBox SubsTxt("with OLD text", "OLD", "NEW")
End Sub

Function SubsTxt(strComment, strOld, strNew As String)
Dim BeforeOld, AfterOld As String

'without error handling!!! strOld must be in strComment!!!
BeforeOld = Left(strComment, InStr(1, strComment, strOld) - 1)
AfterOld = Right(strComment, Len(strComment) - Len(BeforeOld) _
- Len(strOld))
SubsTxt = BeforeOld & strNew & AfterOld
End Function

Best,

Rafael

"John Svendsen" wrote:

Hi All,

I've been looking around for how does one Find and Replace text strings

in
Cell Comments.
There is a lot of info on addind, deleting, text, but I did no find

anything
on replacing/changing existing text.
I've tried
activecell.comment.text Replace(activecell.comment.text, "old", "new")
but no go
Does anyone have any ideas?
Thanks a lot
JS








 
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 inside comments? Knox Excel Discussion (Misc queries) 3 August 31st 07 05:12 PM
find text in cell and replace it with part of the text in that ce. jules Excel Discussion (Misc queries) 3 May 3rd 07 10:18 AM
Find and replace Comments Deba Excel Worksheet Functions 1 June 13th 06 01:39 PM
How do you find and replace text in autoshapes or comments the_lipster Excel Discussion (Misc queries) 0 June 17th 05 12:35 AM
Find and replace for comments in excel 2003 omprakash Excel Discussion (Misc queries) 1 January 28th 05 05:55 AM


All times are GMT +1. The time now is 12:41 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"