+ Reply to Thread
Results 1 to 3 of 3

How can I use a Macro to set a Page break after a character.

  1. #1
    the_Bruce
    Guest

    How can I use a Macro to set a Page break after a character.

    Hello, I would like to create a Macro to set a page break after a line of
    ------ characters.

  2. #2
    Nick Hebb
    Guest

    Re: How can I use a Macro to set a Page break after a character.

    Sub InsertPageBreaks()

    Dim c As Range
    Dim ws As Worksheet

    Set ws = Application.ActiveSheet
    For Each c In ws.UsedRange
    If c.Text = "--------" Then 'or whatever character string you
    want
    ws.HPageBreaks.Add ws.Rows(c.Row + 1)
    End If
    Next

    End Sub


  3. #3
    Mike Fogleman
    Guest

    Re: How can I use a Macro to set a Page break after a character.

    Sub PageBreak()
    Dim c As Range
    Dim myrng As Range
    Dim contents As String
    Dim LastRow As Long
    Dim i As Integer
    Dim e As Integer

    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Set myrng = Range("A1:A" & LastRow)
    For Each c In myrng
    contents = c.Value

    If Len(contents) = Len(contents) - Len(Application.WorksheetFunction. _
    Substitute(contents, "-", "")) Then
    ActiveSheet.HPageBreaks.Add before:=Range("A" & LastRow + 1)
    End If
    Next c
    End Sub

    What the If statement does is: counts the number of characters in each cell
    and compares that number to the number of hyphens in each cell. When those
    numbers match, a page break is added to the following row.
    If your hyphens are not in column A, then adjust the code to match the
    appropriate column.

    Mike F
    "the_Bruce" <the_Bruce@discussions.microsoft.com> wrote in message
    news:39084D66-6428-47DC-92DA-FA48EA586731@microsoft.com...
    > Hello, I would like to create a Macro to set a page break after a line of
    > ------ characters.




+ Reply to Thread

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.6.0 RC 1