为什么循环找不到所有分页符?

时间:2017-09-14 17:20:08

标签: vba excel-vba excel

我正在循环到7000行并查找每个分页符并将其向上移动10行,当它下降3/4时,它会在5500左右停止并留下5-8个分页符不被移动?

可能是因为将它们向上移动它创建了原始循环中不包含的额外分页符吗?如果是这样,我该如何解决?

Dim i As Long
Dim pb As Variant
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
For Each pb In ws.HPageBreaks
    For i = pb.Location.Row To 1 Step -1
         If Cells(i,1) = 1 Then
            ActiveSheet.HPageBreaks.Add before:=Cells(i, 1)
         End If
    Next

Next

0 个答案:

没有答案