Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Stuart Mattinson[_2_] Stuart Mattinson[_2_] is offline
external usenet poster
 
Posts: 3
Default Multipule Tables - Grand Total Formula

I am trying to add the total of multipule tables together, I have the formula
below that I have added to the VBA of "This Document" so that when the
document opens the macro will run.

I have two questions :

1. Where to I place the Format(total, "#,###.00") so that I have the correct
deimal placing in the final total

2. Because I am running the macro every time the document opens I can end up
with the answer multipule times, I could ask the users to run it manually but
sometimes they forget and then the document will be mailed out without a
Grand Total. I have reied to add a Delete before the marco starts but it is
not working 100%

My Current Macro is :

Private Sub Document_Open()
ActiveDocument.Bookmarks("GrandTotal").Select
Selection.Delete
Dim i As Long, total As Double
Dim rsum As Range
total = Format(total, "#,###.00")
With ActiveDocument
For i = 1 To .Tables.Count
Set rsum = .Tables(i).Cell(6, 2).Range
rsum.End = rsum.End - 1
If IsNumeric(rsum.Text) Then
total = total + rsum.Text
End If
Next i
End With
ActiveDocument.Bookmarks("GrandTotal").Select
Selection = "R" & total
End Sub

  #2   Report Post  
Posted to microsoft.public.word.tables
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Multipule Tables - Grand Total Formula

Your macro appears to delete the bookmark you are trying to select later in
the macro.
I take it that you are trying to get the bookmark to hold the result of the
calculation? In that case

Private Sub Document_Open()
Dim i As Long, total As Double
Dim rSum As Range
Dim rBMark As Range
Set rBMark = ActiveDocument.Bookmarks("GrandTotal").Range
With ActiveDocument
For i = 1 To .Tables.Count
Set rSum = .Tables(i).Cell(6, 2).Range
rSum.End = rSum.End - 1
If IsNumeric(rSum.Text) Then
total = total + rSum.Text
End If
Next i
End With
rBMark.Text = "R" & Format(total, "#,###.00")
With ActiveDocument
.Bookmarks.Add "GrandTotal", rBMark
.Fields.Update
End With
End Sub


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




Stuart Mattinson wrote:
I am trying to add the total of multipule tables together, I have the
formula below that I have added to the VBA of "This Document" so that
when the document opens the macro will run.

I have two questions :

1. Where to I place the Format(total, "#,###.00") so that I have the
correct deimal placing in the final total

2. Because I am running the macro every time the document opens I can
end up with the answer multipule times, I could ask the users to run
it manually but sometimes they forget and then the document will be
mailed out without a Grand Total. I have reied to add a Delete before
the marco starts but it is not working 100%

My Current Macro is :

Private Sub Document_Open()
ActiveDocument.Bookmarks("GrandTotal").Select
Selection.Delete
Dim i As Long, total As Double
Dim rsum As Range
total = Format(total, "#,###.00")
With ActiveDocument
For i = 1 To .Tables.Count
Set rsum = .Tables(i).Cell(6, 2).Range
rsum.End = rsum.End - 1
If IsNumeric(rsum.Text) Then
total = total + rsum.Text
End If
Next i
End With
ActiveDocument.Bookmarks("GrandTotal").Select
Selection = "R" & total
End Sub



Reply
Thread Tools
Display Modes

Posting Rules

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2003 Tables not givin right Total until printing Marilyn Microsoft Word Help 4 November 30th 07 03:39 PM
I need to get a grand total from several embedded worksheets.... suziep Microsoft Word Help 0 November 29th 07 06:51 PM
Calculate Total of two different tables, display result in a different table Ben Tables 2 December 22nd 05 02:13 PM
Mailmerge with multipule letters anton Mailmerge 4 April 5th 05 07:29 PM
Formula in table - Creating a final total from sub-total cells Anne Gilmour Tables 1 November 7th 04 04:14 AM


All times are GMT +1. The time now is 07:11 PM.

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"