XL: Replacing Text in Cell Notes

Last reviewed: December 1, 1997
Article 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 Widnows 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 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 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/refguide/default.asp

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 PgmHowto PgmLoop PgmOthr
Version : WINDOWS:5.0,5.0c,7.0; MACINTOSH:5.0
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.