How to insert page breaks when value changes in Excel?

Suppose you have a list of data in a worksheet, and you need to insert page breaks each time the value in column A changes, as shown in the screenshot on the left. Manually inserting page breaks one by one can be time-consuming, especially for large datasets. Fortunately, there are several practical methods available to insert page breaks based on value changes efficiently. This article will detail multiple solutions, covering scenarios both with and without VBA or add-ins, to help you choose the approach best suited for your task.
Insert page breaks when value changes with VBA code
If you need to insert page breaks automatically each time a value changes in a specific column, using VBA can accomplish this efficiently. This method is suitable for users who are comfortable working with Excel macros and want an automated approach.
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module window.
VBA code: Insert page breaks when the value changes:
Sub insertpagebreaks()
'updateby Extendoffice
Dim I As Long, J As Long
J = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For I = J To 2 Step -1
If Range("A" & I).Value <> Range("A" & I - 1).Value Then
ActiveSheet.HPageBreaks.Add Before:=Range("A" & I)
End If
Next I
End Sub
3. Press the F5 key to run this code. Excel will automatically add page breaks at each point where the data in column A changes. See screenshot below:
This VBA approach is very flexible and suitable for large datasets or repeated tasks. However, if you are not familiar with VBA or your environment restricts macros, consider the following alternative methods.
Insert page breaks when value changes with a powerful feature
With Kutools for Excel, you can quickly add page breaks every time values change in a selected column, and also apply other formatting actions, such as inserting blank rows, adding border lines, or filling background color on value change. This feature is especially convenient if you frequently require such data formatting, and it does not require writing or understanding code. Click to download Kutools for Excel.
1. On your worksheet, go to the Kutools tab, then click Format > Distinguish differences. Refer to the screenshot:
2. In the Distinguish differences by key column dialog box:
- Select the data range you want to work with and specify the key column (usually the column where you want to detect value changes).
- Choose Page Break under Options.
3. Click the OK button. Kutools will automatically add page breaks at each point where the specified column's value changes. The screenshot below shows the result:
Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now
This method is particularly user-friendly and helpful for those who do not want to code or manage macros. It is also useful for handling a wide range of similar formatting needs beyond page breaks.
Identify where breaks should go with a formula helper column
You can use an Excel formula to help flag when the value changes in a column, which then guides where manual page breaks should be inserted. While standard formulas cannot insert page breaks directly, they make it easy to spot where breaks are needed. This method is especially useful if you prefer to avoid macros or add-ins and have a small-to-moderate dataset.
Applicable scenarios: Use this approach if you want a visual guide to insert page breaks without any automation, or when working in environments where macros or add-ins are not allowed.
For example, suppose your data is in column A starting from row 2. To identify where values change:
1. Enter the following formula in cell B2:
=A2<>A1
This formula compares each cell in column A with the one above it. It will display TRUE
when the value in A2 is different from A1, indicating a change.
2. Copy the formula down to apply it to other rows.
Now, each TRUE
in column B shows where the value in column A changes. You can manually add a page break immediately before or after each row where a change is indicated.
Alternatively, you can use an IF
formula to make the indication even clearer. Enter the following in B2:
=IF(A2<>A1, "Insert Break", "")
This will display "Insert Break" where the value changes for easier visual scanning.
- Tip: After marking, go through your sheet and insert page breaks at each marked position as needed (Page Layout > Breaks > Insert Page Break).
Pros: No need for code or add-ins, and easy to implement for small or moderate datasets.
Cons: Requires manual insertion of page breaks and may be tedious on very large lists.
More relative articles:
- Highlight Rows When Cell Value Changes In Excel
- If there is a list of repeated values in your worksheet, and you need to highlight the rows based on column A, whose cell value changes as the following screenshot. In fact, you can quickly and easily finish this job by using the Conditional Formatting feature.
- Increment Numbers When Value Changes In Another Column
- Supposing you have a list of values in column A, and now you want to increment the number by 1 in column B when the value in column A changes, which means the numbers in column B increment until the value in column A changes, then the number increment starts from 1 again, as left screenshot. In Excel, you can solve this problem with the following method.
- Sum Cells When Value Changes In Another Column
- When you work on an Excel worksheet, sometimes you may need to sum cells based on a group of data in another column. For example, here, I want to sum the orders in column B when the data changes in column A to get the following result. How could you solve this problem in Excel?
- Insert Blank Rows When Value Changes In Excel
- Supposing you have a range of data, and now you want to insert blank rows between the data when the value changes, so that you can separate the sequential same values in one column as following screenshots. In this article, I will talk about some tricks for you to solve this problem.
- Run Macro When Cell Value Changes In Excel
- Normally, in Excel, we can press the F5 key or the Run button to execute the VBA code. But have you ever tried to run the specific macro code when a cell value changes? In this article, I will introduce some quick tricks to deal with this job in Excel.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
All Kutools add-ins. One installer
Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.





- All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
- One installer, one license — set up in minutes (MSI-ready)
- Works better together — streamlined productivity across Office apps
- 30-day full-featured trial — no registration, no credit card
- Best value — save vs buying individual add-in