Display ASCII Character Codes higher than 255 in appropriate script

nigidivitch

New Member
Joined
Sep 28, 2010
Messages
22
Hi there - I've been trying to get Excel to display high-value ASCII codes but am failing so far...
Basically, I've extracted a load of data from an SQL database, and a large amount of the data is appearing as character codes (e.g. "&#1332 ;" - without the space in between the "2" and the ";") rather than "Դ".
I've tried searching extensively to see whether anyone's worked out how to get excel to search through the column and replace all of the character codes with the characters themselves, but have as yet, not found a solution.

I think the answer to this is probably to use the "ChrW" function in VB, but I'm struggling to write the VB script to search through entire table, finding the character codes and replacing them with the appropriate characters.

If anyone can help me with this it would be amazing! Thanks

N
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi

There are no ascii codes higher than 255 and so I guess you mean Unicode characters.

This worked for me.

I had in A1:A2

This is a test: ☼, ☺, ☼, Ɔ, ☼, Ɔ.

This☼is☺☼another☼testƆ.

<colgroup><col></colgroup><tbody>
</tbody>

and I got as result, as expected:

This is a test: ☼, ☺, ☼, Ɔ, ☼, Ɔ.

This☼is☺☼another☼testƆ.

<colgroup><col></colgroup><tbody>
</tbody>


Try for A1:A10:

Code:
Sub ReplaceCodes()
Dim r As Range, rC As Range
Dim regex As Object, regexMatches As Object
Dim s As String
Dim j As Long

Set r = Range("A1:A10")
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = "(&#(\d{4});)(?!.*\1)"
regex.Global = True

For Each rC In r.SpecialCells(xlCellTypeConstants, xlTextValues)
    s = rC.Value
    Set regexMatches = regex.Execute(s)
    For j = 1 To regexMatches.Count
        s = Replace(s, regexMatches(j - 1).Value, ChrW(regexMatches(j - 1).submatches(1)))
    Next j
    rC.Value = s
Next rC
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

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