+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    11-04-2009
    Location
    Portsmouth
    MS-Off Ver
    2007
    Posts
    20

    Deleting empty rows

    Hi

    I have small problem with VBA in word, I have a payslip report exported to word. Unfortunately payslips are not on one page, but there are various number of carrdge returns between them so one payslip can be on two pages. I am looking for a solution (macro) that would move each payslip so that only one would be on each page (for printing purposes). Do you have any ideas?
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    MSO2007 on WinXP/MSO2000 on Win7
    Posts
    1,958

    Re: Deleting empty rows

    Code:
    Option Explicit
    Sub MakePages()
        'Turn off the search and replace dialog message boxes
        Application.DisplayAlerts = wdAlertsNone
        
        'Begin a new search and replace
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        
        'set up to delete multiple blank lines
        'the sample text has many lines with a
        'single space and a end of paragraph marker
        'and lines with six spaces and a para mkr
        
        With Selection.Find
            .Text = " ^p ^p"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
        End With
        
        'delete them
        Selection.Find.Execute Replace:=wdReplaceAll
        
        With Selection.Find
            .Text = "      ^p"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
        
        'set up to search for the word "VALIDATION" that
        'indicates the start of a new form.
        Selection.MoveDown Unit:=wdLine, Count:=1
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "validation"
            .Forward = True
            .Wrap = wdFindAsk
            .MatchWholeWord = True
        End With
        Do While Selection.Find.Execute
        
            'When found move to the start of the line and insert
            'a hard pagebreak,
            Selection.HomeKey Unit:=wdLine
            Selection.InsertBreak Type:=wdPageBreak
            
            'then move down one line so that the last find is
            'not included in the new search
            Selection.MoveDown Unit:=wdLine, Count:=1
        Loop
        
        'quit without prompting when no longer found
        If Selection.Find.Execute = False Then Exit Sub
        
        'turn ms word alerts back on
        Application.DisplayAlerts = wdAlertsAll
    End Sub
    ---
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    11-04-2009
    Location
    Portsmouth
    MS-Off Ver
    2007
    Posts
    20

    Re: Deleting empty rows

    This works perfect, thank you very much.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0