Excel has no built-in setting or worksheet formula that automatically inserts a page break when a cell contains a chosen value. In desktop Excel for Microsoft 365 on Windows, you can use a short VBA macro to look for a marker such as BREAK in a column and add a horizontal page break above each marked row.
What Excel can and cannot do automatically
Excel places automatic page breaks according to the printable area, paper size, margins, orientation, and scaling settings. Those breaks can move when the worksheet layout changes. You can also add manual page breaks, which tell Excel where a printed page should end, but Excel does not provide a built-in rule such as “insert a break whenever column A changes” or “insert a break when B contains BREAK.”
That distinction matters because a cell formula can calculate a value, but it cannot change the worksheet’s print layout. Functions such as IF or conditional formatting can identify or highlight rows that meet a condition; neither one creates a page break. For a repeatable, cell-driven rule, VBA is the usual solution in desktop Excel. If you only need a one-time break, use the Page Layout ribbon instead.
A horizontal break divides the sheet between rows, so the row below the break begins on a new printed page. A vertical break divides it between columns. The example below inserts horizontal breaks because that is the common case when each marked record or group should start on a new page.
Choose the cell rule before writing a macro
Decide what should trigger a new page and where the marker will go. A dedicated marker column is easy to understand and less likely to cause accidental breaks than searching a column that contains ordinary data. For example, put BREAK in column B on each row that should begin a new page. If row 1 contains headings, the macro can start checking at row 2.
Other useful rules include starting a new page when a department name changes, when a status cell equals a particular word, or when a date crosses into a new month. These are different tests, so be precise about whether the break belongs above the row containing the value or after the preceding group. The sample macro treats a marker as an instruction to start a page above that same row.
- Use a dedicated column if people will add or edit markers by hand.
- Use a consistent marker spelling; the sample ignores capitalization and surrounding spaces.
- Keep the header row out of the marker range unless you deliberately want a break before it.
- Check whether a marker in a formula cell returns the marker text; the macro checks the cell’s calculated value.
Prepare the worksheet and add the VBA macro
This example assumes the active worksheet has headers in row 1 and marker values in column B. It clears existing manual page breaks on that sheet, then inserts a horizontal break before every row where column B contains BREAK. Automatic page breaks are recalculated by Excel as needed; they are not the same as the manual breaks this macro clears and adds.
Option Explicit
Sub InsertBreaksAtMarkers()
Dim ws As Worksheet
Dim markerCol As Long
Dim markerText As String
Dim lastRow As Long
Dim r As Long
Set ws = ActiveSheet
markerCol = 2 ' Column B
markerText = "BREAK"
' Find the last used marker cell in column B.
lastRow = ws.Cells(ws.Rows.Count, markerCol).End(xlUp).Row
' Remove existing manual breaks before rebuilding them.
ws.ResetAllPageBreaks
' Start at row 2 so the header row is not checked.
For r = 2 To lastRow
If StrComp(Trim$(CStr(ws.Cells(r, markerCol).Value2)), _
markerText, vbTextCompare) = 0 Then
ws.HPageBreaks.Add Before:=ws.Rows(r)
End If
Next r
End Sub
To adapt it, change markerCol to the column number you use (A is 1, B is 2, C is 3, and so on), and change markerText to the exact text you want to recognize. The code uses Trim to ignore spaces at the beginning or end and compares without regard to uppercase or lowercase. It determines the last row from the marker column, so a marker below the last nonempty cell in that column will not be found.
Run the macro and save the workbook
On Windows, open the Visual Basic Editor from Developer > Visual Basic. If Developer is not visible, enable it through File > Options > Customize Ribbon and select the Developer check box. In the editor, choose Insert > Module, paste the code into the module, return to Excel, and run it from Developer > Macros by selecting InsertBreaksAtMarkers and choosing Run. You can also run a selected macro with Alt+F8 in Windows.
On a Mac, use Developer > Visual Basic if the Developer tab is available; the keyboard shortcut can depend on the keyboard and function-key settings. Excel for the web does not run VBA macros, so open the workbook in the desktop app to use this approach. After adding VBA, save the file as an Excel Macro-Enabled Workbook (.xlsm), not as a standard .xlsx file, if you need to keep the macro in the workbook.
Make a copy of the workbook before running a macro. VBA actions cannot be undone with Ctrl+Z, and this macro deliberately removes existing manual page breaks before making a new set. If you want to preserve hand-placed breaks, remove the ResetAllPageBreaks line and review how the existing breaks interact with the new ones instead.
Check the breaks in print layout
After the macro runs, choose View > Page Break Preview to inspect the page boundaries. Excel displays page divisions on the worksheet, making it easier to see whether each marked row starts a new page and whether columns spill onto extra pages. Return to Normal view when you finish reviewing. For a final check, open File > Print and look at the print preview; on Windows, Ctrl+P opens the print screen, and on Mac, Command+P is the comparable shortcut.
A page break is a print-layout instruction, not a blank row and not a change to the data. If a marked row is very tall, or the sheet has many columns, the resulting page may still be difficult to read. Adjust column widths, row heights, margins, paper orientation, or print area as appropriate. Also check scaling: fitting a whole worksheet onto a fixed number of pages can change how Excel lays out content, so a page-break preview and the actual print preview are more useful than relying on the marker column alone.
Common problems and how to fix them
- No breaks appear: Check that the marker is in the column specified by markerCol, that it exactly matches markerText apart from case or outer spaces, and that the macro ran on the intended active worksheet. The macro checks the active sheet, not every sheet in the workbook.
- Existing breaks disappear: That is expected because ResetAllPageBreaks clears manual breaks on the active sheet. Remove that line only if you intend to keep earlier manual breaks, and inspect the result for duplicates or unwanted divisions.
- A marker near the top behaves unexpectedly: The loop begins at row 2. If you need a break before row 1, reconsider the layout; a break above the first row usually does not provide a useful page division. Change the starting row only when your sheet structure requires it.
- Pages do not match the marker pattern: Automatic page divisions, print area, paper size, orientation, margins, and scaling all affect printed output. Review Page Break Preview and File > Print, and confirm that the correct worksheet and print settings are in use.
- The macro is missing or blocked: Confirm the workbook is saved in .xlsm format and opened in desktop Excel. Organizational security settings may restrict macros; follow your organization’s rules rather than enabling unknown code.
Alternatives for one-time or non-macro work
For a single break, select the row below where the new page should begin, then choose Page Layout > Breaks > Insert Page Break. Excel places a horizontal break above the selected row. To remove manual breaks, use Page Layout > Breaks > Remove Page Break for a selected break, or Reset All Page Breaks to clear manual breaks on the sheet. These commands do not make the placement respond to future cell-value changes.
If macros are not suitable, you can use the marker column as a checklist and insert breaks manually, or split the data into separate worksheets or print jobs. A formula can display a warning such as “New page” when a condition is met, but someone still has to insert the break. This can be a reasonable choice for a small report that changes infrequently, while a macro is more practical when the same rule must be reapplied after data updates.
Frequently Asked Questions
Can an Excel formula insert a page break?
No. Worksheet formulas return values and cannot edit print settings or insert page breaks. Use the Page Layout command for a one-time change or VBA in desktop Excel for a rule based on cell values.
Can I insert a break whenever a value in column A changes?
Yes, with a VBA condition that compares each row’s value in column A with the previous row. The marker-based macro above is simpler when you can add a dedicated flag; a change-detection rule is preferable when the data itself defines group boundaries.
Will the macro work when a marker is produced by a formula?
It can, because the sample reads Value2, the cell’s calculated value. The formula must return the text BREAK (ignoring case and outer spaces) for the row to qualify, and Excel must have recalculated the result.
Does inserting a page break change the worksheet data?
No. It changes how the worksheet is divided for printing or page-oriented output. It does not add rows, alter cell values, or insert a blank line into the worksheet.
Can I run this macro in Excel for the web?
No. Excel for the web does not execute VBA macros. Open the workbook in desktop Excel for Windows or Mac to run VBA; a manual page break can also be inserted in the desktop app without using a macro.
How do I keep the macro after saving?
Save the workbook as an .xlsm file. Saving as .xlsx does not preserve VBA code, so keep a macro-enabled copy if you want to run the cell-based page-break rule again later.
Related
- Excel Data Validation Dynamic List: Setup and Tips
- Excel Data Validation Dependent Drop-Downs: Setup Guide
- Excel Data Validation Custom Lists: Setup and Tips
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Creating a Signature in Microsoft Outlook: Setup GuideTo create an Outlook signature, open the signature settings for your version of Outlook, add and format the…
- Inventory Spreadsheet in Google Sheets or Google Docs?For an inventory spreadsheet, use Google Sheets rather than the Google Docs word processor. Sheets is built for…
- Add an Image Watermark in Word: A Clear Step-by-Step GuideTo add an image watermark in Microsoft Word for Microsoft 365 on Windows, open the Design tab, choose…
- Excel Keyboard Shortcuts to Delete a RowIn Excel for Microsoft 365 on Windows, press Shift+Space to select the current row, then press Ctrl+- (Ctrl…
- Insert Data From Image in Excel: A Step-by-Step GuideTo insert data from an image in Excel for Microsoft 365 on Windows, open the worksheet, choose Data…
- Excel Page Break Dotted Lines: Meaning and Fixes ExplainedExcel page break dotted lines mark where the worksheet is expected to split across printed pages. To hide…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.