Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pagebreaks not working correctly

Status
Not open for further replies.

RHemmings

Programmer
Mar 24, 2003
6
IN
With the code below, the only way can get the pagebreaks to work is to include the Rows("16:16").Select line. I need to have the pagebreak be variable. However, if I comment out the Rows line and depend on the Cells(z, 1).Select line, I get an error "Runtime error '1004', Application-defined or Object-defined error".

Can some help steer me in the right direction?

Thanks,
Bob

With Selection.CurrentRegion
rc = .Rows.Count
End With
rc = rc + 50
For z = 1 To rc
If Cells(z, 4).Value = "Initial Balance" Then
Cells(z, 1).Select
Rows("16:16").Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
Selection.EntireRow.Insert Shift:=xlDown
Selection.EntireRow.Insert Shift:=xlDown
z = z + 2
End If
Next
 
Have you got your z and 4 the wrong way round?

You may want to ask in the VBA forum forum707. This is a VB5/6 forum.

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top