Format cells in excel for decimal places using a macro

By | February 27, 2018
Questions:

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?

Answers:

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"

Leave a Reply

Your email address will not be published. Required fields are marked *