Cell.AutoSum method (Word)
Inserts an = (Formula) field that calculates and displays the sum of the values in table cells above or to the left of the cell specified in the expression.
Syntax
expression. AutoSum
expression Required. A variable that represents a 'Cell' object.
Remarks
For information about how Word determines which values to add, see the Formula method.
Example
This example creates a 3x3 table in a new document and sums the numbers in the first column.
Dim docNew as Document
Dim tableNew as Table
Set docNew = Documents.Add
Set tableNew = docNew.Tables.Add(Selection.Range, 3, 3)
With tableNew
.Cell(1, 1).Range.InsertAfter "10"
.Cell(2, 1).Range.InsertAfter "15"
.Cell(3, 1).AutoSum
End With
This example sums the numbers above or to the left of the cell that contains the insertion point.
Selection.Collapse Direction:=wdCollapseStart
If Selection.Information(wdWithInTable) = True Then
Selection.Cells(1).AutoSum
Else
MsgBox "The insertion point is not in a table."
End If
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for