vba:错误移动最后一行.HPageBreaks在最后一行

时间:2017-11-03 08:26:31

标签: vba excel-vba row-number page-break excel

我想装页,这样,如果水平页制动器距离最后一行少于8行,则应删除水平页制动器。

m是A列的最后一行:

m = Cells(Rows.Count, "A").End(xlUp).Row + 1 

该宏运行了好几周,但在这种情况下(见图),它失败了(运行时错误' 9')。

failing case

With ActiveSheet.HPageBreaks
    If .Count > 0 Then
    'in this instance: .count = 3, m = 83
        On Error GoTo fine
        If m - .Item(.Count).Location.Row < 8 Then ActiveSheet.HPageBreaks(.Count).DragOff Direction:=xlDown, RegionIndex:=1
     End If
End With

我不明白:如果数为3,为什么不存在行号?

0 个答案:

没有答案