run time error. Please help me.

  • Thread starter Thread starter countryfan_nt
  • Start date Start date
C

countryfan_nt

Hello All,
I have this macro, it page breaks pages however, due to the larg
number of pages I get an error "RUN TIME ERROR 1004". That happen
because the page breaks exceed 1026 pages. Is there anyway to make th
macro stop once it reaches 1026 pages?

Thanks,
Nawaf

Sub STEP3()
Application.Wait Now + TimeValue("00:00:03")

Dim Curr_Base As Long
Dim Prev_Base As Long
Dim i As Long
Dim Loop_Count As Long

ActiveWindow.Activate
Loop_Count = Range(Selection, Selection.End(xlDown)).Count
'MsgBox Loop_Count
For i = 3 To Loop_Count
Range("E" & i).Select
Curr_Base = ActiveWindow.ActiveCell
'MsgBox Curr_Base
If (Curr_Base <> Prev_Base) Then
ActiveWindow.SelectedSheets.HPageBreaks.Add before:=ActiveCell
End If
Prev_Base = Curr_Base
Next i
End Su
 
Maybe you could add:

if ActiveWindow.SelectedSheets.HPageBreaks.Count > 1025 then
'don't do it
else
'go ahead and add it.
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top