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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA count between PageBreaks in excel

Status
Not open for further replies.

VBAGT

Technical User
Feb 14, 2008
3
0
0
BR
Is there a way to count all filled rows and/or cells between two PageBreaks defined manually?

And how can I set a macro to delete the last PageBreak defined manually?

My intention is to correct a problem in this code (used to fix a spreadsheet for printing), which can waste some space between the last two pages:

Sub Macro2()

Dim Linha As Integer
Dim MarcaFinal As Integer

Cells.Select
Cells.EntireRow.AutoFit
Cells.PageBreak = xlPageBreakNone
Linha = 50
MarcaFinal = 0

Line1:
If MarcaFinal = 48 Then
GoTo LineFim
End If

If Mid(Cells(Linha, 4), 1, 3) = "aaa" Then
Worksheets("Plan4").Rows(Linha).PageBreak = xlPageBreakManual
Linha = Linha + 49
MarcaFinal = 0
GoTo Line1
Else
Linha = Linha - 1
MarcaFinal = MarcaFinal + 1
GoTo Line1
End If

LineFim:
MsgBox "Clique aqui."

End Sub
 
Nevermind!


I just put this code before the second If:

If Cells(Linha, 4) = Empty Then
GoTo LineFim
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top