Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.word.tables
|
|||
|
|||
Difference (and SUM) between two columns in a WORD table
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 |
#2
Posted to microsoft.public.word.tables
|
|||
|
|||
Difference (and SUM) between two columns in a WORD table
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 "Tablequery" wrote in message ... 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 |
#3
Posted to microsoft.public.word.tables
|
|||
|
|||
Difference (and SUM) between two columns in a WORD table
Hi wdc,
If you'd prefer to use Word formula fields for this, some examples that demonstrate how to use relative referencing can be found in my Word Field Maths 'tutorial', at: http://www.wopr.com/cgi-bin/w3t/show...?Number=365442 See under "Relative Referencing In Tables" Cheers -- macropod [MVP - Microsoft Word] "Tablequery" wrote in message ... 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 |