Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 Page Break Adjustments causes a page break each cell BKaufman Excel Worksheet Functions 2 September 10th 10 05:02 AM
Page break or Fit to Page Macro wigs Excel Worksheet Functions 0 March 31st 09 09:34 PM
Page Break Macro Daniel R. Young Excel Programming 5 July 26th 05 09:17 PM
Using macro for page break Sara Excel Discussion (Misc queries) 2 January 13th 05 09:29 PM
Page break macro lehigh46 Excel Worksheet Functions 2 November 17th 04 02:00 AM


All times are GMT +1. The time now is 11:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"