Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Getting Rid of Non-Printing Characters Intelligently.

Getting Rid of Non-Printing Characters Intelligently

Written by Allen Wyatt (last updated December 24, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


If you work with files that originate from a non-Excel source, you can sometimes end up with characters in your cells that Excel doesn't know how to display properly. For instance, you may have a comma-delimited text file generated by your company's accounting software, and you load the file into Excel. In some cells you may notice that there are small boxes. These represent non-printing characters. Excel displays the small boxes so that you know the character is there, even though it cannot be displayed or printed.

To get rid of these characters you an try to use the Find and Replace feature of Excel. Try these steps:

  1. Within the cell that contains one of the small boxes, highlight the box and press Ctrl+C. This copies the character to the Clipboard.
  2. Choose Replace from the Edit menu or press Ctrl+H. Excel displays the Replace tab of the Find and Replace dialog box. (See Figure 1.)
  3. Figure 1. The Replace tab of the Find and Replace dialog box.

  4. With the insertion point in the Find What box, press Ctrl+V. This pastes the contents of the Clipboard (the offending character) into the Find What box. The character will most likely not look like the small box you selected and copied in step 1.
  5. If nothing was pasted in step 3, then close the dialog box and try the steps again. If nothing is still pasted, then you won't be able to use Find and Replace to get rid of the non-printing characters, and you can skip the rest of these steps.
  6. If you want to just delete the characters, make sure there is nothing in the Replace With box. If you want to replace the characters with spaces, put a single space in the Replace With box.
  7. Click on Replace All.

This approach may or may not work, depending mostly on Excel and whether it let you accurately copy the offending character in step 1. If it does work, then you have learned a valuable technique for getting rid of the bad characters. If it doesn't work, then you should try a different approach.

One thing to try is to use Word in your "clean up" operations. Copy the data from Excel to a Word document (paste it as regular text), and then replace the offending characters. You can then paste the data back into Excel. Some people report that they get exactly the results they want by using this round-trip approach to working with the data.

You can, of course, use a macro to get rid of the offending characters. It isn't too difficult to create your own version of the CLEAN worksheet function that, instead of simply removing non-printing characters, replaces them with spaces. Consider the following example macro:

Function ReplaceClean1(sText As String, Optional sSubText As String = " ")
    Dim J As Integer
    Dim vAddText

    vAddText = Array(Chr(129), Chr(141), Chr(143), Chr(144), Chr(157))
    For J = 1 To 31
        sText = Replace(sText, Chr(J), sSubText)
    Next
    For J = 0 To UBound(vAddText)
        sText = Replace(sText, vAddText(J), sSubText)
    Next
    ReplaceClean1 = sText
End Function

You use this function in the following manner within your worksheet:

=ReplaceClean1(B14)

In this case, all non-printing characters in cell B14 are replaced with a space. If you want the characters replaced with something else, just provide the text to replace with. The following example replaces the non-printing characters with a dash:

=ReplaceClean1(A1,"-")

The following usage simply removes the non-printing characters, the same as the CLEAN function:

=ReplaceClean1(A1,"")

If you look back at the ReplaceClean1 macro presented earlier, you see that it uses the Replace function. This VBA function is not available in all the versions of VBA used with the different versions of Excel. If you try the macro and you get an error on one of the lines that use the Replace function, then use this version of the ReplaceClean macro instead:

Function ReplaceClean2(sText As String, Optional sSubText As String = " ")
    Dim J As Integer
    Dim vAddText
    Dim aWF As WorksheetFunction
    Set aWF = Application.WorksheetFunction

    vAddText = Array(Chr(129), Chr(141), Chr(143), Chr(144), Chr(157))
    For J = 1 To 31
        sText = aWF.Substitute(sText, Chr(J), sSubText)
    Next
    For J = 0 To UBound(vAddText)
        sText = aWF.Substitute(sText, vAddText(J), sSubText)
    Next
    ReplaceClean2 = sText
    Set aWF = Nothing
End Function

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2947) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Getting Rid of Non-Printing Characters Intelligently.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Printing via Macro without Messages

When you are printing a document, it is not unusual to see messages (dialog boxes) periodically. When you want the ...

Discover More

Making Use of Extra Labels

Got extra labels left over after printing a mail merge? Here's what you can do to put those labels to good use.

Discover More

Anchoring Comment Boxes in Desired Locations

Want your comment boxes to appear someplace other than the right side of a cell? You may be out of luck, and here's why.

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (menu)

Copying to Very Large Ranges

Using the mouse to select a large cell range can be frustratingly slow. If you want to make copying to a large range of ...

Discover More

Changes in Font Size when Copying

Have you ever copied information from one worksheet to another, only to have the information you paste not look the way ...

Discover More

Quickly Entering Data

Excel includes a handy shortcut for entering data that is similar to whatever you entered in the cell above your entry ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six minus 3?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.