Discussion:
Auto Calculate SUM formula in Table
(too old to reply)
Dax Arroway
2010-03-12 18:28:10 UTC
Permalink
I have a blank table (not form) with headers which gets filled in, row by
row, as transactions occur. I'm trying to SUM one of the columns (simple SUM
function). I'm trying { SUM(ABOVE) } which works if the table is already
filled out. But if it's blank and gets filled in, the SUM does not calculate
or update automatically. I'd like it to keep a running tally. I've also
tried { SUM(F2:F17) } excel-like code for the cells of the table I'm trying
to SUM but I get the same results; it only adds information already there.
I'd like it to function like excel does, auto updating as the numbers get
entered. Are there field codes or another way to write this to get it to
happen in a Word03 table?
Thanks in advance,
Dax
--
I would give my left hand to be ambidextrous!
Dax Arroway
2010-03-12 18:50:01 UTC
Permalink
Of course I meant: { =SUM(ABOVE) } and I'm using F9 to insert the curly
brackets not just typing them in. (fingers just type too darn FAST!) *blush*
--
I would give my left hand to be ambidextrous!
Post by Dax Arroway
I have a blank table (not form) with headers which gets filled in, row by
row, as transactions occur. I'm trying to SUM one of the columns (simple SUM
function). I'm trying { SUM(ABOVE) } which works if the table is already
filled out. But if it's blank and gets filled in, the SUM does not calculate
or update automatically. I'd like it to keep a running tally. I've also
tried { SUM(F2:F17) } excel-like code for the cells of the table I'm trying
to SUM but I get the same results; it only adds information already there.
I'd like it to function like excel does, auto updating as the numbers get
entered. Are there field codes or another way to write this to get it to
happen in a Word03 table?
Thanks in advance,
Dax
--
I would give my left hand to be ambidextrous!
Doug Robbins - Word MVP
2010-03-12 21:42:31 UTC
Permalink
Insert an Excel spreadsheet into the document in place of the table
--
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, originally posted via msnews.microsoft.com
Post by Dax Arroway
I have a blank table (not form) with headers which gets filled in, row by
row, as transactions occur. I'm trying to SUM one of the columns (simple SUM
function). I'm trying { SUM(ABOVE) } which works if the table is already
filled out. But if it's blank and gets filled in, the SUM does not calculate
or update automatically. I'd like it to keep a running tally. I've also
tried { SUM(F2:F17) } excel-like code for the cells of the table I'm trying
to SUM but I get the same results; it only adds information already there.
I'd like it to function like excel does, auto updating as the numbers get
entered. Are there field codes or another way to write this to get it to
happen in a Word03 table?
Thanks in advance,
Dax
--
I would give my left hand to be ambidextrous!
macropod
2010-03-13 03:11:58 UTC
Permalink
Hi Dax,

Although Word formulae do calculate automatically, they only do so dynamically in documents using formfields with the 'calculate on
exit' option checked. To get the SUM to update in an ordinary document, you'll need to select that cell and press F9. Alternatively,
do a Print Preview.
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Dax Arroway
I have a blank table (not form) with headers which gets filled in, row by
row, as transactions occur. I'm trying to SUM one of the columns (simple SUM
function). I'm trying { SUM(ABOVE) } which works if the table is already
filled out. But if it's blank and gets filled in, the SUM does not calculate
or update automatically. I'd like it to keep a running tally. I've also
tried { SUM(F2:F17) } excel-like code for the cells of the table I'm trying
to SUM but I get the same results; it only adds information already there.
I'd like it to function like excel does, auto updating as the numbers get
entered. Are there field codes or another way to write this to get it to
happen in a Word03 table?
Thanks in advance,
Dax
--
I would give my left hand to be ambidextrous!
Stefan Blom
2010-03-15 19:19:43 UTC
Permalink
Note that although switching to Print Preview updates many fields, it
doesn't update formula fields (not even if the option to update fields
before printing is selected in Word Options).
--
Stefan Blom
Microsoft Word MVP
Post by macropod
Hi Dax,
Although Word formulae do calculate automatically, they only do so
dynamically in documents using formfields with the 'calculate on exit'
option checked. To get the SUM to update in an ordinary document, you'll
need to select that cell and press F9. Alternatively, do a Print Preview.
--
Cheers
macropod
[Microsoft MVP - Word]
Post by Dax Arroway
I have a blank table (not form) with headers which gets filled in, row by
row, as transactions occur. I'm trying to SUM one of the columns (simple SUM
function). I'm trying { SUM(ABOVE) } which works if the table is already
filled out. But if it's blank and gets filled in, the SUM does not calculate
or update automatically. I'd like it to keep a running tally. I've also
tried { SUM(F2:F17) } excel-like code for the cells of the table I'm trying
to SUM but I get the same results; it only adds information already there.
I'd like it to function like excel does, auto updating as the numbers get
entered. Are there field codes or another way to write this to get it to
happen in a Word03 table?
Thanks in advance,
Dax
--
I would give my left hand to be ambidextrous!
s***@rightster.com
2014-07-15 12:47:29 UTC
Permalink
You can do an auto field update for tables within a Word document by using a little bit of VBA. The process is fairly simple:

1. Press Alt + F11 to get to the VBA Window.
2. In the left panel right-click on your document name and select Insert > Class Module. The name will default to Class1 if no other Class Modules are present which is fine.
3. Add the following code in the main window for this new class module:

Public WithEvents App As Word.Application


Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
ActiveDocument.Fields.Update
End Sub

4. Again in the left panel right-click on document name and select Insert > Module and add this code to the main window:

Dim MyWord As New Class1

Sub Register_Event_Handler()
Set MyWord.App = Word.Application
End Sub


Sub AutoOpen()
Register_Event_Handler
End Sub


5. Save the file at a .docm and open the file. Any fields you now modify will fire any calculations in the table.

One last point is that if you want to use this code within a template file you have to add the above code to the normal.dotm file (search for the file location with Windows Explorer) in the same fashion as shown above. The only change you will need to make is to substitute the phrase 'AutoOpen' with 'AutoNew' in step 4.

Hope this helps a few people. Know Microsoft removed the auto update functionality since Word 2002 to aid processing speed, but think they should definitely at least give you the option to this as a normal process within the latest versions of Word given the processing capabilities of most PC's these days.
s***@gmail.com
2018-07-03 11:12:17 UTC
Permalink
This code needs overhauled! it adds the fields everytime an update is made instead of adding the number in the fields only when a change to that field has changed.
Loading...