我在工作表中循环所有分页符。我在另一个for循环中有一个for循环。当我的条件满足时,我只想退出内部循环,但为什么我的代码退出时仍有更多的中断页面循环?这就是我所拥有的:
FoundRange = Cells.Find(What:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
getLastRow = FoundRange
ActiveSheet.PageSetup.PrintArea = ("$A$1:$Q$" & getLastRow + 500) '*** Need to increase my printarea to accomodate all the pagebreak i was setting along the way, changed to 1000 and it works.
For Each pb In ws.HPageBreaks
For i = pb.Location.Row To 17 Step -1
if i - getLastRow < 14 then
ActiveSheet.HPageBreaks.Add Before:=Cells(getLastRow + 1, 1)
ActiveSheet.PageSetup.PaperSize = xlPaperA4
ActiveSheet.PageSetup.PaperSize = xlPaperLetter
exit for 'also tried goto Here
end if
next
'Here:
next '<< gets here on exit for, but it doesn't loop my next page break. Acts like it is the last page break when I know there is more.