VBA Print Area Syntax

Mozzz

Board Regular
Joined
May 30, 2011
Messages
66
I think I have the variables set up right, but I can't get the PageSetup.PrintArea right.

Here is my code:

Sub SetPrint()
' Setup Print and View 13 Month Trend
Dim EndRow As Variant
Dim TopRow As Variant
Dim NumberOfRows As Integer


NumberOfRows = Cells(Rows.Count, 1).End(xlUp).Row * -1
EndRow = Cells(Rows.Count, 1).End(xlUp).End(xlToRight).Address
TopRow = Cells(Rows.Count, 1).End(xlUp).End(xlToRight).Offset(NumberOfRows + 1, -12).Address
ActiveSheet.PageSetup.PrintArea = TopRow: EndRow


End Sub


What am I doing wrong?

Help!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I got it to work using this line:

With ActiveSheet
.PageSetup.PrintArea = .Range(TopRow, EndRow).Address
End With

I don't understand the period in front of Range.
 
Upvote 0
Probably a better explanation out there but,

The Period "fully qualifies" whatever you are working with.

In your instance, since you had With ActiveSheet, the period lets the code know that you are working with the ActiveSheet and no other.

I do remember reading a post from Lenze on this board that fully explains this, with examples. Just not up to finding it again.
 
Upvote 0

Forum statistics

Threads
1,224,593
Messages
6,179,791
Members
452,942
Latest member
VijayNewtoExcel

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