Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Cleaning Text.

Cleaning Text

Written by Allen Wyatt (last updated January 11, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


2

Excel includes an interesting worksheet function whose duty it is to make sure that your text is "clean." By this, Excel means that your text contains only printable characters. Thus, the function removes certain non-printable characters and control codes from your text. The syntax is rather simple, as follows:

=CLEAN(text)

All you need to do is include the text, or a reference to a cell that contains text. In doing some testing, it appears that the function removes anything with an ANSI value of 1 through 31, as well as the values 129, 141, 143, 144, and 157.

So why would you use the CLEAN function? If you import information from some mainframe or on-line services, the non-printable codes could be interspersed in the information you receive. This can cause problems printing or viewing the information correctly. CLEAN can help rectify those problems.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10350) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Cleaning Text.

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

Disappearing Status Bar

Ever had your Excel status bar disappear unexpectedly? Here's some ideas on why this may be happening.

Discover More

Finding Rows with Values in Two Columns

When you use Excel to input and store information, you need to be concerned with whether the information meets your ...

Discover More

Determining Combinations to Make a Total

If you have a range of cells that contain values, you may wonder which combinations of those cells should be used to meet ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Returning Values to the Left of a VLOOKUP

VLOOKUP is a great function to use in accessing data based on a lookup value. Problem is, you can't easily return ...

Discover More

Returning Item Codes Instead of Item Names

The data validation capabilities of Excel are really handy when you want to limit what is put into a cell. However, you ...

Discover More

Using GEOMEAN with a Large List

When performing a statistical analysis on a large dataset, you may want to use GEOMEAN to figure out the geometric mean ...

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 7 - 7?

2025-01-11 16:29:51

J. Woolley

The TextClean macro in My Excel Toolbox removes ASCII characters 0 through 31 (Tab, CR, LF, etc.) plus ANSI characters 129, 141, 143, 144, and 157. Additional characters can be specified for removal (case-sensitive) including
Alt+nnnn for UNICHAR(nnnn). For more on this subject, see https://excelribbon.tips.net/T006126
The TextSpaceChars macro converts all UNICODE space characters (see Figure 1 below) into a standard ASCII space. For more on this subject, see https://excelribbon.tips.net/T012593
Both macros:
+ Apply to text constants within the current Selection.
+ Retain the format of individual characters (normally).
+ Support Undo (Ctrl+Z).
See https://sites.google.com/view/MyExcelToolbox/

Figure 1. 


2025-01-11 07:03:01

Alex Blakenburg

Unfortunately one of the most common character needing to be removed is the non-breaking space character code 160. For this you will need to use substitute refer: https://excelribbon.tips.net/T005132_Trimming_Off_All_Spaces.html


This Site

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.

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.