vba 使用宏将excel中的单元格格式化为小数位
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12962656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Format cells in excel for decimal places using a macro
提问by TankTank
How can I format Cell (D:) 2 decimals places Cell (E:) 1 decimal place and Cell (H:)3 decimals places in excel using a macro?
如何使用宏在excel中格式化单元格(D:)2个小数位单元格(E:)1个小数位和单元格(H:)3个小数位?
回答by scott
the numberformat property of a range will format it to any custom format
范围的 numberformat 属性将其格式化为任何自定义格式
sheets("sheet1").range("D:D").numberformat = "0.00"
sheets("sheet1").range("E:E").numberformat = "0.0"
sheets("sheet1").range("H:H").numberformat = "0.000"
for numbers with a comma or currency displayed this would work:
对于显示逗号或货币的数字,这将起作用:
sheets("sheet1").range("D:D").numberformat = "&#,##0"