Skip to main content
 

How to insert page breaks when value changes in Excel?

Author: Xiaoyang Last Modified: 2024-10-22
A screenshot of data where page breaks will be inserted when values change

Supposing, I have a range of cells, and now, I want to insert page breaks into the worksheet when values in column A changes as left screenshot shown. Of course, you can insert them one by one, but are there any quick ways to insert the page breaks at once based on the changed values of one column?

Insert page breaks when value changes with VBA code

Insert page breaks when value changes with a powerful feature


Insert page breaks when value changes with VBA code

The following VBA code can help you to insert page breaks below based on once column data changes, please do as follows:

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. Then press F5 key to run this code, all page breaks have been inserted into the sheet when data changes in column A. See screenshot:

A screenshot of the inserted page breaks in Excel when values in column A change

Note: In the above code, A is the column header that you want to insert page break based on, you can change it to your need.

Insert page breaks when value changes with a powerful feature

If you have Kutools for Excel, with its Distinguish differences feature, you can quickly insert page breaks, blank rows, bottom border lines or background color based on the value changes. Click to download Kutools for Excel!

A screenshot of how Kutools for Excel inserts page breaks when value changes

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

1. Click Kutools > Format > Distinguish differences, see screenshot:

A screenshot of selecting the Distinguish Differences option in Kutools tab on the ribbon

2. In the popped out Distinguish differences by key column dialog box, do the following operations:

  • Select the data range and key column that you want to use;
  • Choose Page Break from the Options box.

A screenshot of the Distinguish Differences dialog box

3. Then click Ok button, the page breaks have been inserted into the range based on the value changes see screenshot:

A screenshot of the inserted page breaks in Excel when values in column A change

Kutools for Excel - Supercharge Excel with over 300 essential tools. Enjoy permanently free AI features! Get It Now


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 which cell value changes as the following screenshot shown. 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 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 shown. In Excel, you can solve this job with the following method.
  • Sum Cells When Value Changes In Another Column
  • When you work on Excel worksheet, sometime, 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 value changes, so that you can separate the sequential same values in one column as following screenshots shown. 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 F5 key or Run button to execute the VBA code. But, have you ever tried to run the specific macro code when a cell value changes? This article, I will introduce some quick tricks to deal with this job in Excel.

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

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!