How to type currency symbols in Visual Basic Edito

2019-03-03 22:15发布

There is a project requirement where we need to check a cell for its currency type.

I came across a similar question in this forum (How to check if cell is formatted as Currency?). It explains how to do that for the $ symbol. But I couldn't replace the $ symbol with other currency symbols (for example Indian Rupee, Euro etc.) in Visual Basic Editor. To have other symbols in VBE I have tried the following:

  • Inserted the symbol in Excel using Insert->Symbol option.
  • Copy pasted the symbol in VBE.

But it is pasted as ? in VBE.

Please help me to have currency symbols in VBE. If the above is not possible please suggest a way to identify the currency type of a cell.

2条回答
老娘就宠你
2楼-- · 2019-03-03 22:54

VBA editor is not Unicode.

In order to have Unicode characters in it, you need to use ChrW$, e.g.

Dim Rupee As String
Rupee = ChrW$(&h20A8&)

Also see Unicode string literals in VBA.

查看更多
放我归山
3楼-- · 2019-03-03 23:02

I have an improved version for the answer... use the following code for making the selection in to Indian rupee Symbol with Lakhs crores format, immaterial of your regional settings in Millions format.

Dim rs As String
rs = ChrW$(&H20B9&)
Selection.NumberFormat = "[>=10000000][$" & rs & "-ta-IN] ##\,##\,##\,##0.00;[>=100000][$" & rs & "-ta-IN] ##\,##\,##0.00;[$" & rs & "-ta-IN] ##,##0.00"

Hope this helps.

查看更多
登录 后发表回答