How to insert page breaks when value changes in Excel?
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:
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)
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:
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!
Tips:To apply this Distinguish differences feature, firstly, you should download the Kutools for Excel, and then apply the feature quickly and easily.
After installing Kutools for Excel, please do as this:
1. Click Kutools > Format > Distinguish differences, see screenshot:
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.
3. Then click Ok button, the page breaks have been inserted into the range based on the value changes see screenshot:
Download and free trial Kutools for Excel 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.
The Best Office Productivity Tools
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
- Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
- Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
- Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
- Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
- Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
- Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
- Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
- Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
- More than 300 powerful features. Supports Office/Excel
2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features
30-day free trial. 60-day money back guarantee.
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!