How to determine cell holds currency

Add-in Express™ Support Service
That's what is more important than anything else

How to determine cell holds currency
 
M D




Posts: 11
Joined: 2007-03-29
Hi,

How can I determine that a cell/range holds a currency? I'm investigating this on a English Excel with non-english currencies and I see nothing which could help me say for sure "yes, the value of this range is a currency".

From what I've found out, there is a Currency data type directly available to VBA, and a set of functions to determine the data type. I would guess these can be used to determine currency in VBA, but how does one do it in COM add-in? It seems that currency is represented by decimal .NET type, but I'd guess some other numeric values can also be represented by this type, so just checking for decimal types does not do the job. I was also checking the Style names, NumberFormat etc. but nothing contains anything specific to currency although the cell being investigated is formatted as "Currency" in Excel.

Thanks for any advices. Regards, md.
Posted 30 Mar, 2007 13:20:38 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi M D.

You can use the NumberFormat and NumberFormatLocal properties of the
Excel.Range interface to obtain the data format.
Please read the following article devoted to currency formatting in .NET:
http://www.microsoft.com/globaldev/getWR/steps/wrg_crncy.mspx#ETE



P.S. Note that we take up your forum requests in the order we receive them. Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 31 Mar, 2007 06:43:29 Top
M D




Posts: 11
Joined: 2007-03-29
Thanks for reply, Sergey. So it means there is no way to determine the cell holds currency? From what I've tried, the NumberFormat properties can contain pretty much anything when the cell holds currency (that is when it's set to currency in Excel "Format Cells..." dialog) - it can be the name of the format, but sometimes it is also one of many formatting strings. I fail to see how this could help unmistakably determine that the cell is formatted as currency.

Can you confirm there is no way to determine without any false positives that a cell holds currency? Do I understand it right, that it is only possible to determine that a cell "might hold a currency" by creating a parser for format strings and also checking for format names? And even this algorithm can fail sometimes (new format names in new Excel versions etc.).

Thanks for reply, md
Posted 13 May, 2007 11:52:49 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi M D.

I didn't find any other way to determine the currency format.
Posted 14 May, 2007 09:39:08 Top