XL5: Can't Use Replace Command to Search for Blank Cells

ID: Q111942

The information in this article applies to:

SYMPTOMS

In Microsoft Excel, if you choose Replace from the Edit menu, and you leave the Find What box blank and choose Find Next, Replace, or Replace All to fill blank cells on a worksheet, you receive the following error message:

   Search string must be specified

WORKAROUND

To work around this problem, use any of the following methods.

Method 1: The following method is presented on page 33 in "Microsoft Excel

          Visual Basic for Applications Step by Step," a Microsoft Press
          book.

          1. Highlight the range

          2. From the Edit menu, choose Goto

          3. Choose Special

          4. Select the Blanks check box

          5. Choose OK

          All the blanks in the range are now highlighted. Enter the value
          that you want to replace the blanks with. Now press CTRL+ENTER.
          This places the data in all of the selected cells.

          Note that if the worksheet is completely blank, you will receive
          the error message "No Cells Found."

Method 2: The following Visual Basic procedure prompts you for the text you
          want to enter in blank cells, and replaces the contents of the
          blank cells in the selection with this text.

             Sub Replace_Blanks()
                ' Dimension variables
                Dim Blanks As Object
                Dim ReplaceWith As String
                Dim Cell As Object
                ' Prompt user for string to enter in blank cells
                ReplaceWith = _
                Application.InputBox("Replace blank cells with what?", _
                "Replace String")
                ' Select blank cells in selection
                Selection.SpecialCells(xlBlanks).Select
                ' Defined Blanks as selection
                Set Blanks = Application.Selection
                ' Fill each cell in selection with user input
                For Each cell In blanks
                   Cell.Activate
                   ActiveCell.Formula = replacewith
                Next cell
             End Sub

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Excel for Windows version 5.0c.

MORE INFORMATION

In Microsoft Excel versions earlier than version 5.0, you can replace blank cells with a value by using the Replace dialog box and leaving the Find What box blank. However, in Microsoft Excel version 5.0, you cannot use this method to replace blank cells because you cannot leave the Find What box in the Replace dialog box blank.

REFERENCES

"Microsoft Excel Visual Basic for Applications Step by Step," Reed Jacobson, ISBN is 1-55615-589-1

Additional query words: 5.00 err msg matching data

Keywords          : kbprg 
Version           : 5.00
Platform          : WINDOWS

Last Reviewed: May 17, 1999