Difference (and SUM) between two columns in a WORD table

T

Tablequery

I have a WORD2003 table -- with 4 columns (A, B, C, and D) and 500 rows --
with numbers in each cell in Columns A and B. How can I show the SUMs (An +
Bn) in Coulmn 3 and the DIFFERENCEs (An - Bn) in Column 4?

Is there a way to do all the 500 sums (or differences) with just a few
keystrokes or do I have to repeat the basic calculation 500 times?

Thanks. ...wdc
 
D

Doug Robbins - Word MVP

Running the following macro will do it for the first table in the document:

Dim A As Range
Dim B As Range
Dim i As Long
With ActiveDocument.Tables(1)
For i = 1 To .Rows.Count
Set A = .Cell(i, 1).Range
Set B = .Cell(i, 2).Range
A.End = A.End - 1
B.End = B.End - 1
.Cell(i, 3).Range.InsertBefore Val(A) + Val(B)
.Cell(i, 4).Range.InsertBefore A - B
Next i
End With

I don't know why to get the sum it is necessary to convert the data in the
first and second columns to values. If that is not done, the data is
concatenated rather than summed. If handles the difference correctly
however without such conversion.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top