How to Manage Excel Page Breaks with VBA Macro Code?

Excel is one of the most popular spreadsheets in the world. However, there are many options that Excel can offer. Sometimes the standard features don't suffice. We'll be looking at page breaks and how to create and remove multiple page breaks in Excel. This is all done in just a few lines VBA code. www.office.com/setup

Inserting Page Breaks

You need to print out a report that you are preparing for your boss. There is nothing worse than having pages printed in the wrong place. Instead of manually inserting page breaks where you want them to be, why not use VBA code instead?

Let's first create a macro for a page break. This will allow us to visualize how the code might look. It will be a bit more complicated than that, but it should give you an idea.

Before: Active Cell

As it stands, the code adds a break above an active cell. This is the location where you last placed the cursor. This is a good thing, but it's not what we need. We want multiple breaks at the locations we choose.

You can do this by manually selecting multiple cells using the ctrl keys and then running a VBA program to add page breaks at each location. This is the VBA code that you could assign to a custom-made menu button:

Each breaklocation in Selection Before:= BreakLocation Next

This code loops through a "collection", which you select with your cursor, and adds a new command to each cell.

Removing Page Broken

It's possible to reset the breaks prior to running the code. However, that's entirely up to you. Here is how to get rid of all page breaks in the current sheet.

Active Sheet Reset All Page Breaks

It's easy to adjust the page breaks commands in Excel. This is because you only need to have a bit of knowledge and a willingness to learn something new. Excel's ability to record macros is incredibly powerful. To learn how to do something, you can simply record a macro and then dissect the code to suit your needs.

You can fine-tune your code to suit your needs. Perhaps you need page breaks for every 20 rows or when Sunday falls on a weekday. You can even use data to mark the place you want a break.

Although it is more difficult, the methods for creating macros or VBA codes to solve Excel problems are the same. It all comes down to what you want and what Excel can do for you. www.office.com/myaccount

 

Popular posts from this blog

Office 2019 vs. Office 365: Which Should You Buy?

Learning to work with formulas in Word:

How to Remove Windows Intune From A Computer?