Written by Allen Wyatt (last updated September 19, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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 can try to use the Find and Replace feature of Excel. Try these steps:
Figure 1. The Replace tab of the Find and Replace dialog box.
This approach may or may not work, depending mostly on Excel and whether it let you actually 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 ReplaceClean(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 ReplaceClean = sText End Function
You use this function in the following manner within your worksheet:
=ReplaceClean(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:
=ReplaceClean(A1,"-")
The following usage simply removes the non-printing characters, the same as the CLEAN function:
=ReplaceClean(A1,"")
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6126) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Getting Rid of Non-Printing Characters Intelligently.
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!
Need a quick memory jog when entering a worksheet function? Here's a shortcut that will be invaluable.
Discover MoreDo you need to paste formulas without updating the references in whatever you are pasting? You can accomplish this, ...
Discover MoreEdit a cell in the Formula bar, and Excel highlights the cells referenced in that formula. If you want to see cells ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments