How to insert a page break for every column

mnucci1

New Member
Joined
Mar 29, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi I'm trying to figure out how to insert a page break on every column no matter the amount of columns.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Welcome to the Board!

If you do not want to do it manually, then assuming that row 1 has headers for all columns with data, this little VBA procedure will do that for you:
VBA Code:
Sub MyInsertColPBs()

    Dim lc As Long
    Dim c As Long
    
'   Find last column in row 1 with data
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    
'   Loop through all columns and insert vertical page breaks
    If lc > 1 Then
        For c = 2 To lc
            ActiveWindow.SelectedSheets.VPageBreaks.Add Before:=Cells(1, c)
        Next c
    End If
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top