Microsoft KB Archive/123574

= Replacing Text in Cell Notes =

Article ID: 123574

Article Last Modified on 8/15/2005

-

APPLIES TO


 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0 for Macintosh

-



This article was previously published under Q123574



SUMMARY
Microsoft Excel does not have a menu command to perform global search and replace operations on cell notes. Choosing Replace from the Formula menu only searches cell contents, not cell notes. The following macro examples demonstrate how to search for and replace information in cell notes.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. For a similar example using the Excel 4.0 macro language, see 78644.

To create and run this macro, follow these steps:

  Enter the following in a module sheet: Sub ReplaceCellNotes ' Ask for original string. oldstr = InputBox("replace what?")

' Ask for new string. newstr = InputBox("replace with?")

' If the two numbers are not exactly the same, go into loop. If oldstr <> newstr Then

' For every cell in the selection. For Each c In Selection

' Find the starting location of the string in the note. location = InStr(1, c.NoteText, oldstr, 1)

' If the string has been found, begin the check. If location > 0 Then

' Get the section of the note before the found string. begpiece = Left(c.NoteText, location - 1)

' Separate out the actual search string. foundpiece = Mid(c.NoteText, location, Len(oldstr))

' Get the section of the note after the found string. endpiece = Right(c.NoteText, Len(c.NoteText) _                    - (location + Len(oldstr) - 1))

' Rebuild the note with the first piece, the new ' string, and the last old piece. c.NoteText Text:=begpiece & newstr & endpiece

End If

' Next cell. Next c

End If     End Sub  Select the range of cells on your worksheet that contain the cell notes that you wish to replace. Run the ReplaceCellNotes subroutine.

You will be prompted for the text that you want to find, followed by the text that you want to replace the found text with. The macro make the appropriate changes to your cell notes.

Additional query words: 5.00 7.00 XL

Keywords: kbhowto kbprogramming kbcode KB123574

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.