Set Different Print Areas for Multiple Sheets

scottclayton

New Member
Joined
Apr 20, 2014
Messages
8
Greetings Lovers of Excel,

In making my label printer, I will need to set the print area for multiple sheets based on a range generated in a cell. E.g. Sheet1 might need cells A1:P1200 set as print area, Sheet2 might need cells A1:G694 set as the print area, Sheet3 might not need to be printed, etc..

I have no problem generating a formula to state what the print area for each sheet should be, respectively, but passing that info into VBA has me really stumped. (Using indirect in the Page Setup menu doesn't work after the value has changed—it changes the value to a static reference, which is bizarre). I suspect I'd want to use the Sub Workbook_BeforePrint, but I'm not 100% on that. Anyone have any ideas? I will generally have 3 or more specific sheets selected—using a button-triggered macro that gets a cell value of sheet names and selects those sheets. Any ideas for different ways of going about this if my above-mentioned idea seems like it could be supplanted?

Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
What have you tried in VBA? If a1 contains a valid range reference like $B$1:$C$10 you should be able to use:

Code:
Sub Test()
    With ActiveSheet
        .PageSetup.PrintArea = .Range("A1").Value
    End With
End Sub
 
Upvote 0
Thanks for the reply, Andrew Poulsom.

Although that suggestion works for one sheet, it doesn't work when there are multiple sheets selected—it will only affect the active sheet of the selected sheets. It would be very elegant if it was a set of instructions that says "for the whole workbook, each sheets print area is given in its respective cell Q1" or something, but I don't know if there's a sub that could work like this.
 
Upvote 0
You have to set the print area one sheet at a time. Try this:

Code:
Sub Test()
    Dim Sh As Object
    For Each Sh In ActiveWindow.SelectedSheets
        With Sh
            .PageSetup.PrintArea = .Range("A1").Value
        End With
    Next Sh
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

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