set print area via

Forum home » Delegate support and help forum » Microsoft Excel Training and help » Set Print area via Macros

Set Print area via Macros

resolvedResolved · Low Priority · Version 2016

Sam has attended:
Excel Advanced course

Set Print area via Macros

Set Print area via Macros

RE: Set Print area via Macros

Hi Sam,

Thank you for the forum question. I hope the Excel day was useful.


This cannot be done with the macro recorder but with VBA.

You will need to loop through the worksheets with a For Each loop.

Please test the code below in a copy of the workbook. In the copy open the visual basic editor (Alt F11). In the Project Explorer (left top) right click on the name of the workbook and click Insert Module. Copy the code below and paste it in the module. Run the code.

I have created the code from how I remember your worksheets. Please let me know how it goes. I may need to make some adjustments. If it is working just move it to the right workbook.

Sub SetPrintAreaMulti()
Dim wks As Worksheet
Dim lastCell As Long
Dim LastCol As Variant

For Each wks In ActiveWorkbook.Worksheets
lastCell = wks.Range("c" & Rows.Count).End(xlUp).Row
LastCol = wks.Cells(5, Columns.Count).End(xlToLeft).Column

wks.PageSetup.PrintArea = "a1:" & ColLtr(LastCol) & lastCell + 1
With wks.PageSetup
.CenterHorizontally = True
.Orientation = xlPortrait

.FitToPagesWide = 1
End With
Next wks

End Sub

Function ColLtr(iCol As Variant) As String
If iCol > 0 And iCol <= Columns.Count Then ColLtr = Replace(Cells(1, iCol + 1).Address(0, 0), 1, "")
End Function








Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Fri 7 Jul 2017: Automatically marked as resolved.

 

Training courses

 

Training information:

See also:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Create Charts with One keystroke

Create a graph with one click

1. Select your data.
2. Press F11.
3. You have a graph.

View all Excel hints and tips


Server loaded in 0.06 secs.