Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello, I would like to create a Macro to set a page break after a line of
------ characters. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 befo=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" wrote in message ... Hello, I would like to create a Macro to set a page break after a line of ------ characters. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2007 Page Break Adjustments causes a page break each cell | Excel Worksheet Functions | |||
Page break or Fit to Page Macro | Excel Worksheet Functions | |||
Page Break Macro | Excel Programming | |||
Using macro for page break | Excel Discussion (Misc queries) | |||
Page break macro | Excel Worksheet Functions |