INFO: Excel Limits Number of Manual Page Breaks to 1026 (284916)



The information in this article applies to:

  • Microsoft Office Excel 2003
  • Microsoft Excel 2002
  • Microsoft Excel 2000
  • Microsoft Excel 97 for Windows

This article was previously published under Q284916

SUMMARY

Microsoft Excel has a limit of 1026 manual horizontal page breaks for a worksheet. If you run a macro that attempts to exceed this limit, you may receive the following run-time error message:
Not Enough Memory.
followed by:
Run-time error '1004':
Application-defined or object-defined error
With Microsoft Excel 2002, you receive the following error message:
Run-time error '1004':
This action exceeds the number of page breaks you can manually add to a worksheet. A worksheet can contain up to 1026 horizontal page breaks.

MORE INFORMATION

The following Excel Visual Basic for Applications (VBA) macro illustrates how the error might occur:
Sub Test()
    Dim oSheet As Worksheet
    Set oSheet = ThisWorkbook.Worksheets(1)
    For i = 1 To 2000
        oSheet.HPageBreaks.Add oSheet.Rows(i + 1) '<- Error when i=1027
        Debug.Print i
    Next
End Sub
				

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbinfo KB284916 kbAudDeveloper