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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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

[TABLE="width: 615"]
<colgroup><col></colgroup><tbody>[TR]
[TD]This is a test: &#9788;, &#9786;, &#9788;, &#0390;, &#9788;, &#0390;.

[/TD]
[/TR]
[TR]
[TD]This&#9788;is&#9786;&#9788;another&#9788;test&#0390;.
[/TD]
[/TR]
</tbody>[/TABLE]

and I got as result, as expected:

[TABLE="width: 409"]
<colgroup><col></colgroup><tbody>[TR]
[TD]This is a test: ☼, ☺, ☼, Ɔ, ☼, Ɔ.

[/TD]
[/TR]
[TR]
[TD]This☼is☺☼another☼testƆ.
[/TD]
[/TR]
</tbody>[/TABLE]


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,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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