使用宏格式化Excel中的小数位单元格

时间:2021-06-13 16:58:38

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?

我怎样才能格式化Cell(D :) 2个小数位单元格(E :) 1个小数位和单元格(H:)3个小数位在excel中使用宏?

1 个解决方案

#1


10  

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"

#1


10  

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"