Testing for a unicode character in VBA

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,676
Office Version
  1. 365
Platform
  1. Windows
I got some great help recently in learning how to return extended Unicode characters such as the up and down arrows from a UDF. Now I need to learn how to test for those same codes when read from the worksheet by a different UDF.

Here's my code. The 4 statements after the comments are trying to compare the character from the cell to the global Unicode constant, gMaxCode.
Code:
Public Const gMaxCode As Long = &H2191  'Up arrow

Public Function PCTally(pAMRange As Range) as String
Dim OU As String    'The code character in the cell
NumReadings = pAMRange.Rows.Count

For i = 2 To NumReadings - 1
   OU = Left(pAMRange(i).Text, 1)        'Get code character

'None of these tests works
   If OU = gMaxCode Then AMHi = AMHi + 1
   If ChrW(OU) = gMaxCode Then AMHi = AMHi + 1
   If OU = ChrW(gMaxCode) Then AMHi = AMHi + 1
   If OU = CLng(gMaxCode) Then AMHi = AMHi + 1

Next i
The character is stored in the cell using this code from a different UDF:
Code:
  OverUnder = ChrW(gMaxCode) & Round(pReading - pGood, 0)
 
Please ignore the previous message. It got posted by mistake. I don't see any way to delete it. I'll post something better shortly. Sorry about that.
 
Upvote 0

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.
I found the problem. First I was confusing the character with its Unicode index, a number. Then I was converting them in the wrong direction. Then I was confusing high readings with low readings. Basically, I didn't know which was was up! ?

This all would have been so much easier if VBA would simply display extended Unicode characters both in the Immediate window and the Watch window. ?

Thanks for the help! (y)?
 
Upvote 0
Yeah, but the VBE (and VBA) is really old and MS has no interest in it, so...
 
Upvote 0
It shows up in my watch window.

downarrow.jpg
 
Upvote 0
There is one setting in English version of Windows 10 that many people have no need to bother. In Settings/Time & Language/Language/Preferred Languages, you can add other (non-Latin) languages. This setting is for non-unicode compliance programs, such as VBE, to display unicode characters. I have Chinese added. This is why unicode can be displayed in VBE.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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