Macro to Re Set Print Area

Simonc64

Board Regular
Joined
Feb 15, 2007
Messages
248
Office Version
  1. 365
All

I have found some answers to this from 13 years ago but none seem to do what I'm after.

I have built a pivot table report, that refreshes and formats on the press of a button with macro attached and it works really well. The icing on the cake would be for that macro to also reset the print area every time I refresh the pivot.

The width of the report will never change just the length, as more records are added to the report. Is there any code that I could use to make this happen?

Thanks in advance for all your help!

Simon
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
trying to sort this I came across this code

Sub SetPrintArea()
Dim ws As Worksheet
Dim lastRow As Long
Set ws = ThisWorkbook.Sheets("3+ Analysis")
lastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ws.PageSetup.PrintArea = ws.Range("A1:J" & lastRow).Address
End Sub


Tried attaching to my existing macro and keep getting end sub expected error - anyone with VBA knowledge able to help on this code or the error message?
 
Upvote 0

Forum statistics

Threads
1,206,947
Messages
6,075,798
Members
446,158
Latest member
octagonalowl

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