G
Guest
Hi again:
I fixed some logical errors. This macro works in the debugger but doesn't
run. I'm trying to set page breaks before the start of the next department.
So each department gets their part of the report.
Thanks,
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 "Row:"; iRow
Debug.Print "Found:"; iPageBreakFound
Debug.Print "DeptID:"; iDeptID
If iDeptID > 40 Then
If iPageBreakFound = 4 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 5
End If
ElseIf iDeptID > 39 Then
If iPageBreakFound = 3 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 4
End If
ElseIf iDeptID > 32 Then
If iPageBreakFound = 2 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 3
End If
ElseIf iDeptID > 23 Then
If iPageBreakFound = 1 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 2
End If
ElseIf iDeptID > 8 Then
If iPageBreakFound = 0 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 1
End If
End If
Next iRow
End With
End Sub
I fixed some logical errors. This macro works in the debugger but doesn't
run. I'm trying to set page breaks before the start of the next department.
So each department gets their part of the report.
Thanks,
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 "Row:"; iRow
Debug.Print "Found:"; iPageBreakFound
Debug.Print "DeptID:"; iDeptID
If iDeptID > 40 Then
If iPageBreakFound = 4 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 5
End If
ElseIf iDeptID > 39 Then
If iPageBreakFound = 3 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 4
End If
ElseIf iDeptID > 32 Then
If iPageBreakFound = 2 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 3
End If
ElseIf iDeptID > 23 Then
If iPageBreakFound = 1 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 2
End If
ElseIf iDeptID > 8 Then
If iPageBreakFound = 0 Then
.HPageBreaks.Add before:=.Cells(iRow - 2, 1)
iPageBreakFound = 1
End If
End If
Next iRow
End With
End Sub