Use of .NumberFormat to Format Decimal Places in Excel VBA
<p>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.</p>

<pre><code> 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
</code></pre>

<p>The value now shows only 2 decimal places, but the formula bar is showing a lot more. </p>

<p><a href="https://i.stack.imgur.com/MQO3L.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MQO3L.png" alt="enter image description here"></a></p>

<p>And <code>?Selection.Value</code> in the Immediate Window of VBA console is showing 89.43448051 too. And this gets pasted into my doc. </p>

<p>Why can the <code>.NumberFormat</code> function change it to 2 decimal places? What do I need to change?</p>