change print area based on cell value

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
Hey Everyone,

Not sure if this is possible, but here we go
if Q7 = any #
that will change the print area.

example
if Q7 = 1 change print area to A1: Q22

if Q7 = 50 then change print area A1:Q71

if Q7 = 51 change print area to A1: Q72
And soo on

Any ideas how this can be done?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I use use a macro to do this. Here is the code:

Code:
Sub test1()
Dim EndOfArea

EndOfArea = Worksheets("Sheet1").Range("Q7")


ActiveSheet.PageSetup.PrintArea = "$A$1:$G" & EndOfArea
End Sub

So, essentially, you declare that the end of the print area would be named EndOfArea, which takes its value from the value of cell Q7. If you want you can write EndOfArea + a number you want.
 
Upvote 0
hmmm, I guess you would need a "change event" in the worksheet code, so everytime the cell q7 changes, then your code runs. Or, you could assign the code to a button, and then press the button before printing
 
Upvote 0
Any idea what the worksheet code would be?

I would assume

Q7 change . run macro test1()

any ideas out there what the full code would be?
 
Upvote 0
here is the code for the change event, you need to place it to the worksheet code

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)   
    If Target.Column = 17 And Target.Row = 7 Then
         Call TestPrintArea
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,752
Messages
6,057,150
Members
444,908
Latest member
Jayrey

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