3

If my Unicode character contains more than one hex value in an Excel cell, how do I write a function in Excel to convert it into the corresponding character?

For example: Unicode Hex values in Excel cell: 0B15 0B4D 0B37. Character to be formed out of above values: କ୍ଷ (Odia/Indian language)

2 Answers2

1

With data like:

enter image description here

Install the following User Defined Function (UDF):

Public Function qwerty(r As Range) As Variant
   Dim L As Long, CH As String, CH2 As String
   arr = Split(ActiveCell.Text, " ")
   For Each a In arr
      L = Application.WorksheetFunction.Hex2Dec(a)
      CH = ChrW(L)
      CH2 = CH2 & CH
   Next a
   qwerty = CH2
End Function

Then pick some cell, say cell B1, format it to Arial Unicode MS and enter:

=qwerty(A1)

enter image description here

User Defined Functions (UDFs) are very easy to install and use:

  1. ALT-F11 brings up the VBE window
  2. ALT-I ALT-M opens a fresh module
  3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx

To remove the UDF:

  1. bring up the VBE window as above
  2. clear the code out
  3. close the VBE window

To use the UDF from Excel:

=qwerty(A1)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

and for specifics on UDFs, see:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

Macros must be enabled for this to work!

0

I got it to work because I needed the same thing.

Public Function qwerty(r As Range) As Variant
   Dim arr() As String
   Dim CH As String, CH2 As String
   Dim a As Variant
   a = 0
   arr = Split(r.Text, " ", -1, vbTextCompare)
   For Each a In arr
      CH = Application.WorksheetFunction.Unichar(a)
      CH2 = CH2 & CH
   Next a
   qwerty = CH2
End Function