Search for Non-ASCII Characters

nanda83

New Member
Joined
Dec 8, 2008
Messages
5
Hi all,

Can any one tell me how to search for Non-ASCII characters in EXCEL?


Thanks in advance!

Nanda
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This formula gotten from here will highlight any character over ASCII 48:
Code:
Dim CharCount As Long 
Dim i As Integer 
CharCount = ActiveDocument.Characters.Count '  Count number of characters
Selection.HomeKey Unit:=wdStory ' Go to start of document
 
For i = 1 To CharCount '  Step through each character
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend ' Select character
    If Asc(Selection) < 48 Then ' Check if asc value is less than 48
        Selection. Range.HighlightColorIndex = wdYellow ' If less than 48 highlight in yellow
    End If 
    Selection.MoveRight Unit:=wdCharacter, Count:=1 ' Move to next character
Next
(Ascii 48 is '0' so this searches for non-ascii text but also highlights numbers)
 
Upvote 0
Thanks,

Me being a newbie.. Can you tell me where to place this code?

Or just refer to some site which explains it.
 
Upvote 0
You would need to press Alt-F11 to open VBA, add 'Sub' tags to it, and then run it from the Macro menu in Excel (or press the 'play' button in VBA).
 
Upvote 0
nanda83

What do you mean by 'non-ASCII characters'?

Have you looked at using the CLEAN worksheet function?

Or Find and Replace?

Sal

That code isn't going to work in Excel VBA, it doesn't have a ActiveDocument object.

As far as I know that's part of the Word object model.:)
 
Upvote 0
By non-ASCII characters, I'm guessing the OP means double-byte characters (like Japanese, Chinese or Korean) or non-ascii code sets (Hebrew, Arabic, etc.). Often in my work we get a document which has to be translated from Japanese to English, and we need to remove all Japanese spaces (double-byte spaces), or for instance the °C mark double-byte character.

To wit (if you don't have Japanese support, you'll probably get garbage characters):
°C =/= ℃

Other potential muckups involve characters like ● circles in Japanese fonts instead of bullets or the like.

In regards to the code, my apologies. Couldn't the same sort of thing be done? Search for all characters that don't return ASCII values or somesuch? Since a Japanese character doesn't have an ascii code, it should work I'd think.
 
Upvote 0
Sal

I'm sure it can be done, but like I said the code you posted is for Word not Excel.

There is no ActiveDocument object in Excel, which you can check by opening the VBE (ALT+F11) then opening the Object Browser (F2) and try a search.

I think you'll find the result is 'No items found'.:eek:

I realise this isn't really positive but I also really think we need more information from the OP.:)
 
Upvote 0
I understand that the code won't work -- I did a quick search on google to see if someone had solved it, and pointed out where I had pasted it from. The point that I'm making is that the logic is probably sound. CLEAN() will not solve the problem of non-ascii characters.
 
Upvote 0
Hi all,

Can any one tell me how to search for Non-ASCII characters in EXCEL?


Thanks in advance!

Nanda

What do you want the code to do with them when it finds them? Remove them or highlight them?

You could set up a loop from 1 to 255 and if the point in the loop falls outside 48 - 122 then you can replace that char with ""

Only a few lines of code along the lines of:

Code:
Sub RemoveNoneStandard()
For X = 1 To 255
    If X < 48 Or X > 122 Then
        ActiveCell.Formula = Replace(ActiveCell.Text, Chr(X), "")
    End If
Next
End Sub

You could then of course loop this through your values replacing activecell with the reference.

Cheers

Dan
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,618
Members
449,238
Latest member
wcbyers

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top