XL: Replacing Text in Cell Notes

ID: Q123574


The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0
  • Microsoft Excel for the Macintosh, version 5.0
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0


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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
For a similar example using the Excel 4.0 macro language, see Q78644.

To create and run this macro, follow these steps:

  1. 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 


  2. Select the range of cells on your worksheet that contain the cell notes that you wish to replace.


  3. 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

Keywords : kbcode kbprg PgmOthr PgmHowto PgmLoop
Version : MACINTOSH:5.0; WINDOWS:5.0,7.0; winnt:5.0
Platform : MACINTOSH WINDOWS winnt
Issue type : kbhowto


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.