InsertFormula Method Example

This example creates a table with three rows and three columns at the beginning of the active document and then calculates the average of all the numbers in the first column.

Set MyRange = ActiveDocument.Range(0, 0)
Set myTable = ActiveDocument.Tables.Add(MyRange, 3, 3)
With myTable
    .Cell(1, 1).Range.InsertAfter "100"
    .Cell(2, 1).Range.InsertAfter "50"
    .Cell(3, 1).Select
End With
Selection.InsertFormula Formula:="=Average(Above)"

The example inserts a formula field that's subtracted from a value represented by the bookmark named "GrossSales." The result is formatted with a dollar sign.

Selection.Collapse Direction:=wdCollapseStart
Selection.InsertFormula Formula:= "=GrossSales-45,000.00", _
    NumberFormat:="$#,##0.00"