Reputation:
Anybody knows how to convert or revise this code to convert its answer to two decimal places?
Range("H2:H" & lastCell1).Formula = "=E2/18.33/8"
Thanks!
Upvotes: 0
Views: 71
Reputation: 1546
You can you this
Sheet("yourSheetName").range("yourRange").NumberFormat = "0.00"
but this only applies to visual. If you wana realy change number to two decimal places you need to round it by something like this.
Sheets("sheet3").Cells(6, 3).Value = Round(Sheets("sheet3").Cells(6, 3).Value, 2)
Where you using Round
when second argument is number of decimal places
Edit: also as someone mentioned here, you can use same ROUND
in formula...
Upvotes: 0
Reputation: 2119
Or this ...
Range("H2:H" & lastCell1).Formula = "=ROUND(E2/18.33/8,2)"
Upvotes: 1
Reputation: 11702
Try this:
Dim MyRange As Range
Set MyRange = Range("H2:H" & lastCell1)
MyRange.Formula = "=E2/18.33/8"
MyRange.NumberFormat = "#0.00"
Upvotes: 1