View Single Post
 
Old 01-16-2013, 05:37 AM
Hoochtheseal Hoochtheseal is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Jan 2013
Posts: 1
Hoochtheseal is on a distinguished road
Default Count rows and add blank rows accordingly

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!

Last edited by macropod; 01-29-2013 at 09:16 PM. Reason: Added code tags & formatting
Reply With Quote