简体   繁体   English

在excel 2007 vba中应用用户定义的格式

[英]apply user-defined format in excel 2007 vba

The excel 2007 format i am using is: #,##0.00,,,_);[Red](#,##0.00,,,);"-" 我正在使用的Excel 2007格式为: #,##0.00,,,_);[Red](#,##0.00,,,);"-"

if is is possitive, i want the number to display in billions; 如果可能的话,我希望显示的数字以十亿为单位; if negative, in billions and in parentahis; 如果为负,则以十亿为单位并以括号为单位; if missing, "-". 如果丢失,则为“-”。

It works fine with excel 2007. But when i tried to apply the format in vba, it did not work. 它可以在excel 2007中正常工作。但是,当我尝试在vba中应用该格式时,它不起作用。

Please use the following numbers as example: 请使用以下数字为例:

-11467478 -11467478
224785.66 224785.66
-5579046 -5579046
1904770.9 1904770.9
-14916968 -14916968

The data type i used is variant. 我使用的数据类型是变量。 shall i use long? 我可以用多长时间?

my initial code is something like: 我的初始代码是这样的:

......
with worksheet
'cells(1,1) would be any of the above numbers
  .Cells(1, 1).NumberFormat = "#,##0.00,,,_);[Red](#,##0.00,,,);" - ""
end with
.....

I got an erros message run-time error 13, type mismatch 我收到一条错误消息run-time error 13, type mismatch

I even tried to decompose the format. 我什至试图分解格式。 but it still did not work. 但是它仍然没有用。

i am quite new to vba. 我是vba的新手。 could anyone help me? 谁能帮我吗? ...... ......

这也将起作用,破折号是不需要转义的字符之一...

"#,##0.00,,,_);[Red](#,##0.00,,,);-"

You need to use double " for the minus sign. I tested your values and I think it should be: 您需要对负号使用double " 。我测试了您的值,我认为应该是:

.NumberFormat = "#,##0.00,,,_);[Red](#,##0.00,,,);""-"""

customNumberFormat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM