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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

BobUmlas

Well-known Member
Joined
Mar 14, 2002
Messages
1,181
Instead of using:
.Orientation = xlLandscape
use:
If ActiveSheet.UsedRange.Columns.Count>10 then .Orientation = xlLandscape else .Orientation = xlPortrait
 
Upvote 0

Forum statistics

Threads
1,195,923
Messages
6,012,317
Members
441,690
Latest member
CyberWrek

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
Top