Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Tablequery
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.word.tables
macropod
 
Posts: n/a
Default 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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:37 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"