Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
countryfan_nt
 
Posts: n/a
Default run time error. Please help me.


Hello All,
I have this macro, it page breaks pages however, due to the large
number of pages I get an error "RUN TIME ERROR 1004". That happens
because the page breaks exceed 1026 pages. Is there anyway to make the
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 befo=ActiveCell
End If
Prev_Base = Curr_Base
Next i
End Sub


--
countryfan_nt
------------------------------------------------------------------------
countryfan_nt's Profile: http://www.excelforum.com/member.php...o&userid=11051
View this thread: http://www.excelforum.com/showthread...hreadid=376839

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Maybe you could add:

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



countryfan_nt wrote:

Hello All,
I have this macro, it page breaks pages however, due to the large
number of pages I get an error "RUN TIME ERROR 1004". That happens
because the page breaks exceed 1026 pages. Is there anyway to make the
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 befo=ActiveCell
End If
Prev_Base = Curr_Base
Next i
End Sub

--
countryfan_nt
------------------------------------------------------------------------
countryfan_nt's Profile: http://www.excelforum.com/member.php...o&userid=11051
View this thread: http://www.excelforum.com/showthread...hreadid=376839


--

Dave Peterson
  #3   Report Post  
Junior Member
 
Location: Ohio
Posts: 19
Default

Personally I would just add an error handler to it. Added screenupdating =false and noticed a bit of a speed improvement he

Sub STEP3TEST()
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

With Application
.ScreenUpdating = False

On Error GoTo ErrHandle
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 befo=ActiveCell
End If
Prev_Base = Curr_Base
Next i

ErrorExit:
.ScreenUpdating = True
End With
Exit Sub
ErrHandle:
MsgBox "Limit Reached"
GoTo ErrorExit
End Sub



Quote:
Originally Posted by countryfan_nt
Hello All,
I have this macro, it page breaks pages however, due to the large
number of pages I get an error "RUN TIME ERROR 1004". That happens
because the page breaks exceed 1026 pages. Is there anyway to make the
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 befo=ActiveCell
End If
Prev_Base = Curr_Base
Next i
End Sub
__________________
Justin Labenne
www.jlxl.net

Last edited by JustinLabenne : June 7th 05 at 01:34 AM
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
time differences in a column 68magnolia71 Excel Worksheet Functions 3 May 9th 05 09:46 PM
Time Sheet Calculation Help Needed! sax30 Excel Worksheet Functions 2 April 26th 05 08:08 PM
Time Sheets Lady Layla Excel Discussion (Misc queries) 1 March 23rd 05 03:22 PM
unmet challenge boris Excel Worksheet Functions 2 March 16th 05 02:13 PM
time formatting and time categorizing (vlookup or data validation) MarianneR Excel Worksheet Functions 4 November 18th 04 03:24 PM


All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"