Format cells in excel for decimal places using a macro

无人久伴 提交于 2020-01-01 17:37:22

问题


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?


回答1:


the numberformat property of a range will format it to any custom format

  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"


来源:https://stackoverflow.com/questions/12962656/format-cells-in-excel-for-decimal-places-using-a-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!