VDB Print Macro - Page Orientation

kalexan3

New Member
Joined
Apr 17, 2013
Messages
2
I have the following code. On some of my tabs, I need to print in portrait and others landscape. I saw some code that did a column count. If the coumn count is less than 10, do portrait, else do landscape.

I wasn't able to get it to work. Any help would be great.

Sub setupSheets()

Dim tempSheet As Worksheet

For Each tempSheet In Worksheets

tempSheet.Activate

With ActiveSheet.PageSetup

.PrintTitleRows = "$1:$10"
.Orientation = xlLandscape
.PaperSize = xlPaperA4
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False

End With

ActiveSheet.Cells.Select
Selection.RowHeight = 14
Selection.EntireColumn.AutoFit
Range("A1").Select

Next tempSheet

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Instead of using:
.Orientation = xlLandscape
use:
If ActiveSheet.UsedRange.Columns.Count>10 then .Orientation = xlLandscape else .Orientation = xlPortrait
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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