Inserting a row

G

Guest

Good day everyone,

On an excel spreadsheet, I'd like to insert a row every 16 rows. Then I'd
like to insert a copy of the first row and then again an empty row adding a
footer saying Page X of X....

Would someone know how I could write this in VBA ?

Thanks for your time

Denys
 
T

Tom Ogilvy

Sub BB()
Dim i As Long, j As Long
i = 1
j = 1
Do While Not IsEmpty(Cells(i, 1))
i = i + 1
j = j + 1
If j = 17 Then
Rows(i).Insert
j = 1
i = i + 1
End If
Loop
End Sub

inserts the rows. Change i to reflect the first row in the data that you
want separated into rows of 15. For example, if you have

row1 Header
row2
row3 1
.. . .
row18 16

then you would set i to 3

I don't know what you mean by insert a copy of the first row and an empty
row.

The footer is confusing as well. Sounds like you are missing Excel's built
in capabilities If you want to print sections of 16 rows, then put in
pagebreaks instead of rows. Use the rows to repeat at top in the 3rd tab of
page setup to indicate your header row and the blank row.
Then you can use a standard custom footer. (View=>Header and Footer)

Sub BBB()
Dim i As Long, j As Long
i = 3
j = 1
Do While Not IsEmpty(Cells(i, 1))
i = i + 1
j = j + 1
If j = 17 Then
ActiveSheet.HPageBreaks.Add Before:=Rows(i)
j = 1
End If
Loop
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$2"
.CenterFooter = "Page &P of &N Pages"
End With
End Sub
 
G

Guest

Hi Tom.

Thank you very much...This is going to be extremely helpful..

Have a nice weekend

Denys
 

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