Hi all
This is my first time attempting to use Word Macros and have copied some code from the internet. This is the code:
Code:
Sub Summarise()
'
' Summarise Macro
'
'
Application.ScreenUpdating = False
Dim i As Integer, FldPos As Range
With ActiveDocument
For Each oPara In .Paragraphs
With oPara.Range
If .Information(wdWithInTable) = True Then
With .Next
If .Information(wdWithInTable) = False Then
If .Text = vbCr Then .Delete
End If
End With
End If
End With
Next
For i = 1 To .Tables.Count
With .Tables(i)
.Rows.Add
Set FldPos = .Cell(.Rows.Count, .Columns.Count).Range.Characters.Last
With FldPos
.Move wdCharacter, -1
.Fields.Add FldPos, Text:="=SUM(ABOVE) \# ""'Total: '£,0""", PreserveFormatting:=False
.Fields.Unlink
End With
End With
Next
End With
Application.ScreenUpdating = True
End Sub
The macro above joins two tables together following a mail merge, then adds a row at the bottom of the table and sums the last column, which is what I want. But, what i'm also after is for each page to have the same number of rows, no matter how many rows of data there are. So something that counts the rows and inserts enough rows to make it up to, say, 20 rows. THEN adds a row and sums it.
Possible?
The other problem I have is that i have 2 other tables on the page and the macro runs on those tables too. I was thinking of putting something in that said if the table has more than 2 rows, then run the macro above, else don't. Alas my VB skills are limited - if you know how i would do this too that would be very handy.
Thanks in advance!