How to insert a page break every 10 lines

E

excellearner

Hi,

I have been stumped on this one. I have been trying to write a macr
for days on inserting a page break every 10 lines and haven't been abl
to figure it out. I will have have to write a macro to insert a blan
row every two lines.

Thanks,
Ev
 
C

Chip Pearson

Eva,

The following code will insert a page break every 10 rows. Change the
values of StartRow and EndRow to meet your needs.


Dim RowNdx As Long
Dim StartRow As Long
Dim EndRow As Long

Dim WS As Worksheet
Set WS = ActiveSheet

StartRow = 11 '<< CHANGE
EndRow = 100 '<< CHANGE

For RowNdx = StartRow To EndRow Step 10
WS.HPageBreaks.Add before:=Rows(RowNdx)
Next RowNdx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

Gord Dibben

Eva

Chip looked after the page breaks. This code will insert a blank row every
two rows. Or did you mean "alternating rows"? In that case, change the
Step -2 to Step -1

Sub InsertALTrows()
'David McRitchie, misc 2001-06-30
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Integer
For i = Selection(Selection.Count).Row To Selection(1).Row + 1 Step -2
Rows(i).EntireRow.Insert
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Gord Dibben XL2002
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top