Unable to remove an Invisible character in a worksheet cell using VBA.

I am unable to identify and remove an extended character from cells in a worksheet.
The data comes from an download (Oracle I think).
The unwanted characters are invisible characters (assumed to be an in the extended character set).
These characters are in the first and last character positions of each cell.
I was able to identify them with the =LEN() function which gave the character string length of 2 characters more than the number of visible characters.
When it check it from VB with the 'ASC' function it incorrectly indicates that it is ASCII character 63 (which is the Question Mark and is a visible character).
But if I test that first character against a "?", it resolves to FALSE (further indicating the VB incorrectly identifies this character).

The main reason for trying to remove these characters is that the VLOOKUP() function fails to match these cells against another worksheet with these data strings that originated from another source and truly do not have these extended characters.

My goal is to be able to identify and remove these unwanted characters with a VB macro, so a VLOOKUP() can be properly performed.
(A workbook is attached with a sample of the problem cells)
Unidentified-Extended-characters.xlsx
LVL 1
Jeff GeiselmanIT Tech AssocAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
You didn't succeed in attaching your workbook. You need to upload the workbook before clicking 'Submit'.
0
Rgonzo1971Commented:
Hi,

instead of ASC then try ASCW to find Unicode Chars

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim RiddlesPrepress/OMS SpecialistCommented:
What you want to use is the Clean() function.  See the following Microsoft article for more information: WorksheetFunction.Clean Method (Excel).
Range("A1").Value = Application.WorksheetFunction.Clean(Range("A1"))

Open in new window

1
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Dr. KlahnPrincipal Software EngineerCommented:
Possible alternative solution:

Export the data as a CSV file.  Then (assuming that the hidden characters are all the same strings), remove them using a text editor.  Then read the CSV back in.
0
aikimarkCommented:
The ASCW values for the characters in A9 are:
 1             8237 
 2             78 
 3             32 
 4             53 
 5             54 
 6             50 
 7             50 
 8             53 
 9             55 
 10            8236 

Open in new window

0
aikimarkCommented:
Please test this:
Public Function ReallyClean(ByVal parmCellText) As String
    Static oRE As Object
    If oRE Is Nothing Then
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
        oRE.Pattern = "[^ -~]"
    End If
    ReallyClean = oRE.Replace(parmCellText, vbNullString)
End Function

Open in new window

0
aikimarkCommented:
If you need to preserve some Cr, Lf, or Tab characters, you can extend the range like this:
Public Function ReallyClean(ByVal parmCellText) As String
    Static oRE As Object
    If oRE Is Nothing Then
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
        oRE.Pattern = "[^\x00-\x7f]"
    End If
    ReallyClean = oRE.Replace(parmCellText, vbNullString)
End Function

Open in new window

0
Jeff GeiselmanIT Tech AssocAuthor Commented:
Rgonzo1971, thanks for pointing me to the ASCW() function.  I had overlooked the possibility of it being UNICODE.
aikimark, thanks for the alternate function.

PS:  The clean() function does not appear to remove the this Unicode character.

Thanks to all for the quick responses!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.