Print Area Error in VBA code - setting page breaks

KThatcher

Board Regular
Joined
May 25, 2006
Messages
135
One last question on this project (I hope)....

I am setting up the print area for my data dependant on the number of sheets per page inputted by the user, the total range on the data (last column value contained in cell A21), and the number of columns to fit to a page.
See below...
I get an error 1004 on Set ActiveSheet.VPageBreaks(i).Location = Range(Cells(21, i).Value)
Also, this is someone else's code, so I guess I don't really get what is happening in that line anyways. Isn't that stepping over to the right? so if i=2 it is selecting from column B, etc...



Dim i As Integer

With ActiveSheet.PageSetup
.PrintTitleRows = "17:20"
.PrintTitleColumns = "$A:$Z"
.PrintArea = "$A$1:$" & Range("A21").Value & "$" & 21 + 5 * Range("L21").Value 'A21 has a text value of the column header
.Zoom = 100
.Zoom = False
.FitToPagesWide = Range("B21").Value 'B21 is the number of pages the user wants to print the data on (typically between 1 and 4)

End With

ActiveWindow.View = xlPageBreakPreview

If Range("B21").Value >= 2 Then

For i = 1 To Range("B21").Value - 1

Set ActiveSheet.VPageBreaks(i).Location = Range(Cells(21, i).Value)

Next i

End If
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,215,364
Messages
6,124,509
Members
449,166
Latest member
hokjock

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