I got the following snippet of code in a Function which is supposed to set the data body range of many columns in an Excel table to the "Currency" format:
For i = 5 To oActiveTable.ListColumns.count
With oActiveTable.ListColumns(i).DataBodyRange
' .NumberFormat = "#,##0.00 €"
' .NumberFormat = "Currency"
.Style = "Currency"
End With
Next
The commented lines are the unsatisfactory or borken attempts, respectively.
.NumberFormat = "#,##0.00 €"
works, but causes the format to show up as "Custom" This is undesired, as it may cause people building on top of my approach to continue this bad practice.
.NumberFormat = "Currency"
doesn't work (error 1004 - obvious, in hindsight), some digging around in docs, tutorials and articles showed that "Currency" is actually a cell style.
.Style = "Currency"
works, i.e. a style is set, but somehow becomes the "Accounting" style - which is not what I want, as we do not want the "- €" for 0 (zero) values.
Why does this happen, and how can I prevent it?
I'm pretty sure I'm not the first to be stumped by this, but searching for it didn't turn up much - most people seem to resort to setting number formats directly.
I'm using Excel 2010 on Windows 7. Both are set to English for the UI language, but the systems has its regional settings (time, date, number formats, ...) set to Germany.
Edit: At least the confusing aspect on my part is solved: the Currency style has the Accounting number format assigned.
#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]
. I wouldn't be too concerned about the "Custom" name. – Arminius Aug 24 '17 at 9:02