The CLEAN function in Excel is a Text formula designed to eliminate "non-printable" characters from a text string. This function proves exceptionally useful when dealing with text imported from external sources that may contain unsupported characters. In this guide, we will delve into the ins and outs of using the CLEAN function in Excel. Furthermore, we'll provide you with essential tips to make your data-cleaning tasks more efficient.

The primary purpose of the CLEAN function is to remove all nonprintable characters from a given text. This feature proves especially handy when working with text imported from various applications, which may contain characters that don't display correctly within your operating system. As an example, CLEAN can effectively strip away low-level computer code often found at the beginning or end of data files, ensuring that your text is ready for seamless printing and further analysis.


Supported Versions

  • All Excel versions

The CLEAN Function in Excel Syntax

In Excel, the CLEAN function has a straightforward syntax, as illustrated below:

CLEAN(text)

text: This is the text you wish to clean.



Using the CLEAN Function with Static Text or Cell References

Example 1: Using the CLEAN Function in a Static Text

=CLEAN("2 + 2

equals

5")

In this example, the CLEAN function processes the static text "2 + 2 equals 5" and removes all non-printable characters, including newline characters. As a result, the text is transformed into a single line.

 

 

 

 

 

 

 

 

 

Example 2: Using the CLEAN Function in a Cell Reference

Alternatively, you can use a cell reference in the CLEAN function. For instance, if cell A1 contains the text

"2 + 2

equals

5"

you can achieve the same result with the following formula:

=CLEAN(A1)

In both cases, the CLEAN function effectively eliminates non-printable characters, ensuring that the text appears as a single, clean line.

Using the CLEAN and TRIM Functions to Remove Extra Space in Excel

Example 3: Combine the CLEAN and TRIM Functions

In Excel, you can combine the CLEAN and TRIM functions to effectively remove any extra spaces within a text string. This is particularly useful when dealing with data that may contain unnecessary spaces, leading to inconsistencies or formatting issues.

"  Excel    is       amazing         "

To clean up this text and remove the extra spaces, you can use a formula in another cell, such as B1. Here's how to do it step by step:

In cell B1, enter the following formula, which uses both CLEAN and TRIM functions:

=CLEAN(TRIM(A1))

This formula first applies the TRIM function to remove leading, trailing, and extra spaces within cell A1. Then, it further ensures that any remaining non-printable characters are removed by applying the CLEAN function. Press the Enter key to execute the formula.

Cell B1 will now display the cleaned and trimmed text:

"Excel is amazing"

As you can see, the combination of the CLEAN and TRIM functions efficiently removed extra spaces and ensured that the text was neatly formatted and ready for further analysis or presentation.

 Download Workbook


Using the CLEAN Function for Non-Printable Characters

The Excel CLEAN function proves to be a tool when dealing with text strings imported from external sources, such as HTML pages. It simplifies the process of removing non-printable characters, enhancing the readability and usability of your data.

When you apply the CLEAN function, it effectively targets and removes non-printable 7-bit ASCII characters, which are represented by values ranging from 0 to 31. These characters, often unseen and unwanted, can create formatting issues or display problems. By using CLEAN, you ensure that your text remains clean and presentable.

However, it's important to note that the CLEAN function does not address all non-printable characters universally. In particular, it ignores non-printable characters within the Unicode character set, including values 127, 129, 141, 143, 144, and 157. Therefore, if your imported text contains such characters, you may need to employ alternative methods for their removal or handling.

To eliminate leading, trailing, or extra spaces (represented by ASCII code 32) within your text, the TRIM function is the recommended choice. Unlike the CLEAN function, TRIM focuses specifically on space-related character adjustments, ensuring a neat and well-organized appearance for your data.