Hello, I would like to create a Macro to set a page break after a line of
------ characters.
Hello, I would like to create a Macro to set a page break after a line of
------ characters.
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
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" <[email protected]> wrote in message
news:[email protected]...
> Hello, I would like to create a Macro to set a page break after a line of
> ------ characters.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks