Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. 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: Converting to ASCII Text.

Converting to ASCII Text

Written by Allen Wyatt (last updated December 8, 2021)
This tip applies to Excel 2007, 2010, 2013, and 2016


5

Brenda has a lot of information that has been imported or pasted into a worksheet. Sometimes the text in the worksheet will contain "foreign" and strange characters. She wonders if there is a way to easily convert the data so that it contains no non-ASCII characters and, perhaps, some foreign characters are converted to regular ASCII values (such as converting accented letters to non-accented letters).

There are a couple of things you can try. First, you can use the CLEAN worksheet function to get rid of non-printable characters. Just use the function in this manner:

=CLEAN(A1)

The result is "cleaned" text, without the non-printables. If you want to replace foreign characters with regular ASCII characters, that will need to be done with a macro. Here's an example of a relatively straightforward approach:

Sub StripAccent()
    Dim sAcc As String
    Dim sReg As String
    Dim sA As String
    Dim sR As String
    Dim i As Integer

    sAcc = "ŠŽšžŸÀÁÂÃÄ�...ÇÈÉÊËÌÍÎÏÐ�'�'�"�"ÕÖÙÚÛÜÝàáâãäåçè�©êëìí�®ïðñòóôõöùúûüýÿ"
    sReg = "SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeiiiidnooooouuuuyy"

    For i = 1 To Len(sAcc)
        sA = Mid(sAcc, i, 1)
        sR = Mid(sReg, i, 1)
        Selection.Replace What:=sA, Replacement:=sR, _
          LookAt:=xlPart, MatchCase:=True
    Next
End Sub

The macro steps through the characters in the sAcc variable and, one at a time, uses Find and Replace to replace them with the corresponding character in the sReg variable. You can adjust the contents of sAcc and sReg to reflect your conversion needs; the key is to make sure that they are both the same length.

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 (11493) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Converting to ASCII 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

Managing the AutoCorrect List

If you need to delete all the entries in your AutoCorrect list, the easiest way to do so is with a macro. This tip ...

Discover More

Accessing a Problem Shared Workbook

What are you to do is you share a workbook with others, and then suddenly the workbook won't open properly? Dealing with ...

Discover More

Pulling Filenames into a Worksheet

You can use Excel for all types of data processing. You may want to work with filenames in a worksheet, but the first ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Defining Shortcut Keys for Symbols

Do you need to use symbols frequently in your Excel data? The common way to insert them is by using the Symbol dialog ...

Discover More

Deleting All Rows Except for the End of Month

If you use a worksheet to track day-to-day data, you might want to delete all of the data except the data for the last ...

Discover More

Moving and Selecting Rows

If you need to move down a row and then select that row, you may wonder if there is a shortcut to handle such a ...

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 6 + 5?

2021-12-10 11:54:10

BJThomasJr

I checked the comments to gather helpful info and noticed some opening comments stating:

"The macro in this tip is really sloppy work" "Obviously..." "a dozen of useless characters" "my version of the macro (smaler as usual :-) that does the job properly"

While the opinions may be true, does the opening sentence often set a "tone" and "expectation" for the reader?

Because for me, I think of conflict, attacks and argumentative posturing however all I really want is well presented information.

Please make your points more inclusive to allow many audiences to share and learn from them... even for timid, uneducated readers like myself?

Respectfully, BJT


2021-12-08 10:21:25

Willy Vanhaelen

I'm perplexed! The text of this tip starts with (last updated June 19, 2018) but Allen or his co-worker didn't take any notice of my comment of 26 Aug 2017 reporting a severe bug in the macro, it still fails to work.

Today i got a "Daily Nugget" referring to this tip with still the cripple macro... That's bad publicity !


2017-08-29 12:17:06

Willy Vanhaelen

@Ru Lopi
If you want to do it with a UDF this smaler function will do it much faster since it has only one loop:

Function StripAccent(sText As String) As String
Dim X As Integer, Y As Integer
Const sAcc = "ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÓÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöùúûüýÿ"
Const sReg = "SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeiiiidnooooouuuuyy"
For X = 1 To Len(sText)
Y = InStr(sAcc, Mid(sText, X, 1))
If Y Then Mid(sText, X, 1) = Mid(sReg, Y, 1)
Next X
StripAccent = sText
End Function


2017-08-28 08:40:55

Ru Lopi

The following will replace foreign characters in a cell.

In a module place this code:

Function funcStripAccent(strText As String) As String

Dim sAcc As String
Dim sReg As String

Dim intInner As Integer
Dim intOuter As Integer

sAcc = "ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÓÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöùúûüýÿ"
sReg = "SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeiiiidnooooouuuuyy"

For intOuter = 1 To Len(strText)

For intInner = 1 To Len(sAcc)

If Mid(strText, intOuter, 1) = Mid(sAcc, intInner, 1) Then
Mid(strText, intOuter, 1) = Mid(sReg, intInner, 1)
End If

Next intInner

Next intOuter

funcStripAccent = strText

End Function

Assuming that the foreign text is in A1 then in the destination cell enter: =funcStripAccent(A1)
This can be fllled to other cells as required.

As mentioned, sAcc and sReg must be the same length with matching conversion characters.


2017-08-26 14:30:11

Willy Vanhaelen

The macro in this tip is really sloppy work. When you copy and paste it in VBA the "sAcc = ..." row gets entirely blood red meaning there is an error. This is because at 2 places in the string there is a single quotation mark which is not allowed . When you remove them you can run the macro but it replaces all the characters in the selected text with an o (ooooooo...)!!!.

Obviously the sAcc and sReg strings should be exactly the same length which is not the case here. The sAcc string is much longer and contains beside the 2 quotation marks a dozen of useless characters including some question marks. These causes the erroneous result. The last question mark in the sAcc string corresponds to the letter o in the sReg string so when sA contains a ? , Replace considers this as a wild card and replaces all the characters in the selection with an o which is the content of sR at that moment.

Here is my version of the macro (smaler as usual :-) that does the job properly:

Sub StripAccent()
Const sAcc = "ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåçéèêëìíîïðñòóôõöùúûüýÿ"
Const sReg = "SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeeiiionooooouuuuyy"
Dim X As Integer
For X = 1 To Len(sAcc)
Selection.Replace _
What:=Mid(sAcc, X, 1), _
Replacement:=Mid(sReg, X, 1), _
LookAt:=xlPart, MatchCase:=True
Next
End Sub


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.