VBA /macro to print only visible data

thorpyuk

Well-known Member
Joined
Mar 14, 2006
Messages
1,453
Hi Guys,

I have a sheet thats created automatically from a load of filtered data. Unfortunately, this does mean that there's loads of 'empty' cells that seem to be picked up as valid, meaning that any print preview will show my data bunched up in the corner!

Does anyone have any code that will 1) auto-set the print area to only cells that have data in them, and 2) automatically select landscape layout + fit to 1 page? (all my data should go on 1 page always)

Thanks!
 
Can anyone else shed some light on this one?

It prints landscape fine, but wont fit to 1 page...
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,

Can anyone shed some light on why my code isn't working superbly!

Code:
Private Sub CommandButton1_Click()
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveSheet.PageSetup.PrintArea = Selection.Address
    ActiveSheet.PageSetup.Orientation = xlLandscape
    ActiveSheet.PageSetup.FitToPagesWide = 1
    ActiveSheet.PageSetup.FitToPagesTall = 1
    ActiveSheet.PrintOut
Range("A1").Select
End Sub

It prints, landscape, but without fitting to 1 page only...
 
Upvote 0

Forum statistics

Threads
1,216,109
Messages
6,128,875
Members
449,476
Latest member
pranjal9

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