Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2013, 05:37 AM
Hoochtheseal Hoochtheseal is offline Count rows and add blank rows accordingly Windows 7 32bit Count rows and add blank rows accordingly Office 2010 32bit
Novice
Count rows and add blank rows accordingly
 
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
  #2  
Old 01-29-2013, 09:23 PM
macropod's Avatar
macropod macropod is offline Count rows and add blank rows accordingly Windows 7 64bit Count rows and add blank rows accordingly Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could simply replace:
.Rows.Add
with something like:
Code:
                While .Rows.Count < 20
                  .Rows.Add
                Wend
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
PPS: You should declare all variables before using them - your oPara variable is undeclared and should be decalred as 'Dim oPara As Paragraph'
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count rows and add blank rows accordingly rows in word? j2b3 Word Tables 3 07-19-2012 03:59 PM
Count rows and add blank rows accordingly hidden rows gsrikanth Excel 5 01-19-2012 02:40 PM
Count rows and add blank rows accordingly merging rows and creating sub-rows gib65 Excel 2 12-09-2011 02:09 PM
Count rows and add blank rows accordingly How to remove blank rows from a specified range? Learner7 Excel 1 04-19-2011 02:45 AM
Count rows and add blank rows accordingly Rows to Columns kyakobi Excel 5 12-07-2010 03:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft