I am inserting data into a Word doc from an Excel spreadsheet. There is a value that has more than 2 decimal places. I am using the following code to try to convert it to 2 decimal places and paste it to my doc.
wdApp.Selection.GoTo what:=-1, Name:="Device_Avail"
''Referring to the total count column in the Device Availability worksheet.
Set devAvailRow = shDevAvail.Range("A:A").Find("Overall Totals:",
After:=Cells(1, 1), searchdirection:=xlPrevious)
''Actual piece to format value to 2 decimal places.
shDevAvail.Cells(devAvailRow.Row, 3).NumberFormat = "0.00"
devAvailPer = shDevAvail.Cells(devAvailRow.Row, 3)
wdApp.Selection.TypeText devAvailPer
The value now shows only 2 decimal places, but the formula bar is showing a lot more.
And ?Selection.Value
in the Immediate Window of VBA console is showing 89.43448051 too. And this gets pasted into my doc.
Why can the .NumberFormat
function change it to 2 decimal places? What do I need to change?