Can't Use Replace Command to Search for Blank Cells

This article was previously published under Q111942
This article has been archived. It is offered "as is" and will no longer be updated.
In Microsoft Excel, if you choose Replace from the Edit menu, and you leavethe Find What box blank and choose Find Next, Replace, or Replace All tofill blank cells on a worksheet, you receive the following error message:
Search string must be specified
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 forillustration only, without warranty either expressed or implied, including,but not limited to the implied warranties of merchantability and/or fitnessfor a particular purpose. The Visual Basic procedures in this article areprovided 'as is' and Microsoft does not guarantee that they can be used inall situations. While Microsoft support professionals can help explain thefunctionality of a particular macro, they will not modify these examples toprovide added functionality, nor will they help you construct macros tomeet your specific needs. If you have limited programming experience, youmay want to consult one of the Microsoft Solution Providers. SolutionProviders offer a wide range of fee-based services, including creatingcustom macros. For more information about Microsoft Solution Providers,call Microsoft Customer Information Service at (800) 426-9400.
Microsoft has confirmed this to be a problem in the Microsoft productslisted at the beginning of this article. This problem was corrected inMicrosoft Excel for Windows version 5.0c.
In Microsoft Excel versions earlier than version 5.0, you can replace blankcells with a value by using the Replace dialog box and leaving the FindWhat box blank. However, in Microsoft Excel version 5.0, you cannot usethis method to replace blank cells because you cannot leave the Find Whatbox in the Replace dialog box blank.
"Microsoft Excel Visual Basic for Applications Step by Step,"Reed Jacobson, ISBN is 1-55615-589-1
err msg matching data XL5

Article ID: 111942 - Last Review: 12/04/2015 10:00:49 - Revision: 1.3

Microsoft Excel 5.0 Standard Edition

  • kbnosurvey kbarchive kbprogramming KB111942