You can insert a page break in Excel VBA with the PageBreaks.Add method on a worksheet: ActiveSheet.PageBreaks.Add Before:=ActiveSheet.Rows(20) adds a horizontal break above row 20, and using a column reference adds a vertical break. This works on any worksheet in Excel for Windows and Mac, and it is the fastest way to control where printed pages split when you have many rows or columns.

What You'll Need

  • Microsoft Excel (desktop version; the VBA editor is not available in Excel for the web).
  • A workbook saved as .xlsm (macro-enabled) if you want to keep the code.
  • Basic familiarity with opening the VBA editor (Alt+F11 on Windows, Fn+Option+F11 on Mac).
  • A worksheet with data, ideally in Page Break Preview (View > Page Break Preview) so you can see where breaks land.

Step-by-Step

  1. Open the VBA editor. Press Alt+F11 (Windows) or Fn+Option+F11 (Mac). If the Project Explorer is not visible, press Ctrl+R. Labels and shortcuts can differ slightly by Excel version and region.
  2. Insert a module. In the Project Explorer, right-click your workbook name, choose Insert > Module. A blank code window appears.
  3. Write a simple horizontal break macro. Type the following, replacing the row number with where you want the break to appear above:
    Sub InsertHorizontalBreak()
        ActiveSheet.PageBreaks.Add Before:=ActiveSheet.Rows(20)
    End Sub
    This inserts a horizontal page break above row 20.
  4. Write a vertical break macro. Use a column reference instead of a row reference:
    Sub InsertVerticalBreak()
        ActiveSheet.PageBreaks.Add Before:=ActiveSheet.Columns("F")
    End Sub
    This inserts a vertical break to the left of column F.
  5. Run the macro. Place the cursor inside the subroutine and press F5, or go back to Excel and use Developer > Macros, select the macro, and click Run. If the Developer tab is hidden, right-click the ribbon and choose Customize the Ribbon to enable it.
  6. Check the result. Switch to View > Page Break Preview. The new break appears as a dashed blue line. Drag it if you need to adjust the position.
  7. Insert multiple breaks in one go. Loop through an array of row numbers:
    Sub InsertMultipleBreaks()
        Dim r As Variant
        For Each r In Array(15, 30, 45)
            ActiveSheet.PageBreaks.Add Before:=ActiveSheet.Rows(r)
        Next r
    End Sub
    Each number is the row above which a break is inserted.
  8. Clear existing breaks first if needed. If your sheet already has manual breaks, remove them before adding new ones to avoid duplicates:
    ActiveSheet.ResetAllPageBreaks
    This removes all manual page breaks on the active sheet but leaves automatic breaks in place.
  9. Save the workbook as .xlsm. Use File > Save As and choose Excel Macro-Enabled Workbook. A standard .xlsx file will discard the macro.

Common Mistakes

  • Using a row that already has a break. Adding a break directly above an existing manual break raises a runtime error. Clear breaks first with ResetAllPageBreaks.
  • Forgetting that breaks are sheet-specific. ActiveSheet only affects the sheet you are on. Use Worksheets("Sheet1") to target a specific sheet by name.
  • Expecting breaks to survive a print area change. If you set a new print area, manual breaks outside it are ignored. Set the print area first, then add breaks.
  • Saving as .xlsx. Macros are stripped on save. Always use .xlsm.
  • Assuming breaks work in Page Layout view the same way. Page Break Preview is the reliable place to see and drag manual breaks.

Tips

  • Use ActiveSheet.HPageBreaks and ActiveSheet.VPageBreaks to count or inspect existing breaks before adding new ones.
  • Combine breaks with PageSetup.PrintArea and PageSetup.Orientation in the same macro so a single run prepares the sheet for printing.
  • Insert breaks relative to data, not fixed row numbers, by finding the last row with Cells(Rows.Count, 1).End(xlUp).Row and calculating from there.
  • Test macros on a copy of the workbook first; page breaks are easy to add but tedious to remove by hand if you add too many.

Troubleshooting

If the macro does not run, check that macros are enabled in the Trust Center (File > Options > Trust Center > Trust Center Settings > Macro Settings) and that the workbook is saved as .xlsm. If you get a "Method 'Add' of object 'PageBreaks' failed" error, the row or column you referenced already has a manual break, or the sheet is protected. Unprotect the sheet (Review > Unprotect Sheet) and clear existing breaks before retrying. If the break appears in the wrong place, confirm you are referencing the row above the content you want on the new page, not the row where the content starts. On Mac, some ribbon labels differ slightly, but the VBA object model is the same.

Frequently Asked Questions

Can I insert a page break without VBA?

Yes. Select the row or column, then go to Page Layout > Breaks > Insert Page Break. VBA is useful when you need to repeat the same breaks across many sheets or workbooks.

Does this work in Excel for the web?

No. Excel for the web does not include the VBA editor. You need the desktop version of Excel.

How do I remove all page breaks with VBA?

Use ActiveSheet.ResetAllPageBreaks. This removes manual breaks but keeps automatic ones that Excel inserts based on paper size and margins.

Can I add a break after a specific row instead of before?

Yes. To break after row 20, reference row 21: ActiveSheet.PageBreaks.Add Before:=ActiveSheet.Rows(21).

Why does my break disappear after printing?

Manual breaks can be lost if the print area changes or if the sheet is reset. Reapply the macro after adjusting print settings, or include break insertion in the same macro that sets the print area.

Do page breaks affect formulas or data?

No. Page breaks only affect printing and print preview; cell values, formulas, and formatting are unchanged.