In this post, we will show you how to remove non-printable characters in Excel. The first 32 characters in the ASCII character table (a standard data-encoding format for communication between computers) are non-printable characters. These characters aren’t displayed (or printed) but tell the application how to format the data. Backspace (ASCII Code 08), Carriage Return (ASCII Code 13), Horizontal Tab (ASCII Code 09), and Line Feed (ASCII Code 10) are some examples of non-printable characters.
When you import or paste data from an external source into Microsoft Excel, you may end up having some non-printable characters in your worksheet. Excel represents such characters as boxes. In this post, we will show you how you may identify and clean these characters from your Excel data.
How to remove Non-printable Characters in Excel?
We will discuss the following two methods to remove non-printable characters in Excel:
- Use the SUBSTITUTE() function to remove non-printable characters
- Use the CLEAN() function to remove non-printable characters
Let us have a detailed look at both of these methods
Use the SUBSTITUTE() function to remove non-printable characters in Excel
Excel offers a CODE() function which returns the ASCII code for a given character. This is basically the reverse of the CHAR() function which is used to translate a numerical code into a character. Once you identify the non-printable character using the CODE() and the CHAR() functions, you may use the SUBSTITUTE() function to substitute (or replace) the character with an empty string.
The syntax of the CODE() function is:
- Where text is the text string for which the ASCII character code (for the first character) is required.
The syntax of the CHAR() function is:
- Where number is a numeric value between 1-255 (Extended ASCII character codes).
And, the syntax of the SUBSTITUTE() function is:
SUBSTITUTE(text, old_text, new_text, [instance_num])
- text refers to the text string in which a substring needs to be replaced.
- old_text refers to the substring that needs to be replaced with new_text.
- new_text refers to the substring to replace old_text with.
- [instance_num] refers to the instance of old_text which needs to be replaced with new_text. If this argument is not specified, each occurrence of the old_text is replaced with new_text.
Now suppose we have a worksheet wherein we have an example string in cell A1, as shown in the above image. The string contains a non-printable character on the extreme right. To remove this character from the string, we may use the above functions in the following way:
Place the cursor in cell B1. Type the following formula in the formula bar on top:
Note: Since the character appears on the right of the original text string, we have used the RIGHT() function to get the last character from the string and then find its ASCII value using the CODE() function.
When you press the Enter key, the above function will return 11, which is the ASCII code for Vertical Tab taken in this example.
Now place your cursor in cell A2 and enter the following formula:
As a result of the function, the non-printable character will be removed from the original string.
Read: 10 Text functions in Excel with examples.
Use the CLEAN() function to remove non-printable characters in Excel
The CLEAN() function in Excel removes all non-printable characters from a given text string. It is the easiest and the most direct way of removing non-printable characters in Excel.
The syntax of the CLEAN() function is:
- Where text represents the text string from which the non-printable characters need to be removed.
For the above example, we may use the CLEAN() function to remove non-printable characters in the following way:
Simple? But, the reason, why we are covering it later, is that it only removes characters that have character codes ranging between 0-31 in the ASCII character table. So it will not remove non-breaking spaces ( ) that may sneak in when you copy/paste data from some external source.
A non-breaking space is a space that can’t be broken by the ‘word wrap’ feature in word processors and other application software. If you want to remove all non-printable characters as well as the non-breaking spaces from a text string, you need to use the CLEAN() function, the SUBSTITUTE() function, and the TRIM() function together.
TRIM() function can be used to trim spaces from both ends of a given string. It is used to fix irregular spacing in Excel.
The syntax of the TRIM() function is:
- Where text refers to the text string from which the leading and trailing spaces need to be removed.
160 is the ASCII code for non-breaking space. Use the CHAR() function to get the character value for non-breaking space. Then use the SUBSTITUTE() function to replace the non-breaking space with normal space. And then use the TRIM() function to remove all spaces from both ends of the original text string.
For the above example, we may use the following formula to remove non-printable characters and non-breaking spaces from the original string:
I hope you find the above post helpful.
Read Next: Excel Toolbar not working.