works in debugger but doesn't run

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This macro works when I step through it.
It compiles also, but doesn't run.
There is no run time error.
I wonder if the stepping syntax is wrong?
Thanks




Private Sub SSPPageBreak()

Dim firstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim iDeptID As Long

Dim iPageBreakFound As Integer
'initialize variables

iRow = 0
iPageBreakFound = 0

With ActiveWorkbook.Worksheets("Sheet1")
firstRow = 2
LastRow = .Cells(.Rows.Count, 16).End(xlUp).Row
For iRow = firstRow To LastRow
iDeptID = .Cells(iRow, 16).Value

Debug.Print iRow
Debug.Print iPageBreakFound
Debug.Print iDeptID


If iDeptID > 8 Then


If iPageBreakFound = 0 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)

iPageBreakFound = 1
End If

ElseIf iDeptID > 23 Then
If iPageBreakFound = 1 Then
.HPageBreaks.Add before:=.Cells(iRow + 1, 1)
iPageBreakFound = 2
End If

ElseIf iDeptID > 32 Then
If iPageBreakFound = 2 Then
.Cells(iRow, 16).Value.PageBreak = xlPageBreakManual
iPageBreakFound = 3
End If

End If
Next iRow
End With
End Sub
 
What are you up to here?

..Cells(iRow, 16).Value.PageBreak = xlPageBreakManual

That seems very odd.
 
Back
Top