View Single Post
  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP
 
Posts: n/a
Default Totaling merged data in new document

The following macro will add a row at the bottom of the table and in the
first cell of that row, it will insert the word "Total" and in the second
cell, it will insert the total of the amounts in column 2 of the table.

Dim i As Long
Dim TotalDollars As Double
Dim atable As Table
Dim currange As Range
Dim newrow As Row
Set atable = ActiveDocument.Tables(1)
TotalDollars = 0
For i = 1 To atable.Rows.Count
Set currange = atable.Cell(i, 2).Range
currange.End = currange.End - 1
TotalDollars = TotalDollars + Val(currange)
Next i
Set newrow = atable.Rows.Add
newrow.Cells(1).Range.InsertAfter "Total"
newrow.Cells(2).Range.InsertAfter Format(TotalDollars, "$#,###.00")


--
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

"Roy Carlson" wrote in message
news
Yeah I got that. But I'm wanting a way to automate this. You see, I work
with people who don't know a lot about formulas and what not. I'd like to
set it up to d it automatically. I'm thinking that a macro would do it,
but
I have only written simple macros or edited macros that are already
written.
I've never started one from scratch like this.

"Doug Robbins - Word MVP" wrote:

I should have mentioned that the row needs to be inserted after executing
the mailmerge.

--
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

"Roy Carlson" wrote in message
...
I've tried that. When I complete the merge, however, I get a total for
each
row, and not a total for all rows at the end of the document. Am I
missing
something?

"Doug Robbins - Word MVP" wrote:

Simplest to set up the mergefields in a table and then add a row at
the
bottom of the table and insert a formula from the tools menu.

--
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

"Roy Carlson" Roy wrote in message
...
How do I total several dollar amounts in a mail merge directory and
show
that
total at the end of the mail merge, under the column that contains
the
merge
data? For example:
[merged data from csv file]
PersonA DollarAmount
PersonB DollarAmount
PersonC DollarAmount
[after merge is done]
TotalDollarAmount