How to insert page breaks when value changes in Excel?
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:
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!
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:
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
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!