Can I use VBA to add cells (over blanks) then do multiplication

P

Peter

I have a Word table in which the last column contains numbers (3 and 4) and
some bank cells and I want it add them and put the total into the second last
row (7 in this case). The last row contains a multiplier (3) which when
applied to the total results in 21. Below is the table.
| | | 3 |
| | | |
| | | 4 |
| | | 7 |
| | 3 |21|
How can I achieve this in VBA (under Word 2003 and 2007) remembering that
the user can add rows to the table and the last column can contain blank
cells.

Thanks in advance for any assistance,

Peter Evans
 
G

Greg Maxey

Sub ScratchMaco()
Dim oTbl As Word.Table
Set oTbl = Selection.Tables(1)
oTbl.Cell(oTbl.Rows.Count, oTbl.Columns.Count).Range.Text = 3 *
fcnTallySubTotal(oTbl)
End Sub
Function fcnTallySubTotal(ByRef Table As Word.Table) As Double
Dim i As Long
For i = 1 To Table.Rows.Count - 2
On Error Resume Next
fcnTallySubTotal = fcnTallySubTotal + CDbl(Left(Table.Cell(i,
Table.Columns.Count).Range.Text, Len(Table.Cell(i,
Table.Columns.Count).Range.Text) - 2))
On Error GoTo 0
Next i
End Function
 
Top