![]() |
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. |
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 |
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 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. |
All times are GMT +1. The time now is 06:06 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com