Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Insert row after pagebreak

I have a set of data with several horizontal pagebreaks.
I would like to write a macro which insert 2rows after a pagebreak is
found.

The idea I have is use .Count and if it's true, return the .Location
and Insert row.
But I don't know how to exactly write the codes

Greatly appreciate if someone can help.
Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Insert row after pagebreak

amepluie wrote:

I have a set of data with several horizontal pagebreaks.
I would like to write a macro which insert 2rows after a pagebreak is
found.

The idea I have is use .Count and if it's true, return the .Location
and Insert row.
But I don't know how to exactly write the codes

Greatly appreciate if someone can help.
Thanks.



Phillip london UK
The following code works for me

I tested it using the following data

in a new workbook in sheet1
select cell A11 then insert a pagebreak
select cell A20 then insert a pagebreak
select cell A29 then insert a pagebreak
Enter numbers 1 to 30 in range A1:A30

In a standard module enter the following procedure

Sub testHPB()
Dim x As Long
Dim z As Long
Dim Rng As Range
Dim Rng1 As Range
Dim Rng2 As Variant

x = Sheet1.HPageBreaks.Count
If x = 0 Then Exit Sub

For z = 1 To x
With Sheet1
Set Rng = Range(.HPageBreaks(z).Location.Address).Resize(1,
1).EntireRow
Set Rng1 = Range(.HPageBreaks(z).Location.Address).Offset(1). Resize(2,
1).EntireRow
Rng1.Insert
Set Rng2 = Rng.Offset(2).EntireRow
Rng.Copy (Rng2)
Rng.ClearContents
End With
Next

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Insert row after pagebreak

Thanks Martin and Phillip. Really appreciate yourhelp.

Both codes work! Thanks so much! Martin's code only insert one row
though.

I do have another question with the codes by the way:

The code seems to run until the limit of the HPageBreak is reach
(around 1000).
Is there someway to reduce that so macro will stop when there's no more
entry to cell?

Thanks once again!!!!
Ame

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
Insert pagebreak when a specific word appears in a column. Neal Excel Discussion (Misc queries) 4 October 27th 08 11:17 PM
Cant move pagebreak in PageBreak View in Excel2003 Vasanthan Excel Worksheet Functions 1 August 22nd 07 03:28 PM
INSERT HORIZONTAL PAGEBREAK AFTER EACH LINE IN ENTIRE WORKSHEET . KNPALIA Excel Worksheet Functions 1 October 27th 06 05:46 PM
insert pagebreak after a specific column? Macroman Excel Programming 0 August 3rd 06 12:16 PM
How to pagebreak Bilal A F Excel Programming 1 November 13th 03 06:57 PM


All times are GMT +1. The time now is 05:16 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"