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
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,752
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
 

Forum statistics

Threads
1,082,345
Messages
5,364,817
Members
400,814
Latest member
gangstar67

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top