Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default replace defined text with page break in vba + excel

I have a text file imported into excel.
I have a varying number of cells in column A containing text ="xxx" that I
would like to replace with a page break when running a macro
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default replace defined text with page break in vba + excel

If you haven't received an answer from somewhere else, perhaps this will
help. It will remove any existing page breaks on the selected sheet and then
insert new ones at the rows containing the specified text in column A of that
row.

Sub AddPageBreaks()
Dim LC As Long ' a loop counter
'Delete any existing page breaks on the sheet
For LC = ActiveSheet.HPageBreaks.Count To 1 Step -1
ActiveSheet.HPageBreaks(LC).Delete
Next
'now add page break above any cell with text "a1" in it
For LC = 1 To Range("A" & Rows.Count).End(xlUp).Row
If Range("A1").Offset(LC, 0) = "a1" Then
ActiveSheet.HPageBreaks.Add Befo=Range("A1").Offset(LC, 0)
End If
Next
End Sub

If you need the text to be at the bottom of the page instead of at the top
of the next, then change the code to read:
ActiveSheet.HPageBreaks.Add Befo=Range("A1").Offset(LC+1, 0)


"BillyH" wrote:

I have a text file imported into excel.
I have a varying number of cells in column A containing text ="xxx" that I
would like to replace with a page break when running a macro

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
Is it possible to replace a series of characters by a page break? Sue Clay Excel Discussion (Misc queries) 13 May 25th 07 12:32 AM
using text wrap how can I type over the page break point Mike Dewar Excel Worksheet Functions 2 May 22nd 06 06:06 AM
adding a new page break to an existing page break Edward Letendre Excel Discussion (Misc queries) 1 March 6th 05 09:29 AM
Search and replace by page break Emiel Excel Programming 2 February 24th 04 01:36 PM


All times are GMT +1. The time now is 05:35 AM.

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

About Us

"It's about Microsoft Excel"