Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2007 Page Break Adjustments causes a page break each cell | Excel Worksheet Functions | |||
Is it possible to replace a series of characters by a page break? | Excel Discussion (Misc queries) | |||
using text wrap how can I type over the page break point | Excel Worksheet Functions | |||
adding a new page break to an existing page break | Excel Discussion (Misc queries) | |||
Search and replace by page break | Excel Programming |