问题
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