Using a macro to change the print area on a non-selected sheet

Bri2000

New Member
Joined
Feb 19, 2018
Messages
3
Hello,

I have been scouring this forum trying to find an answer to this question (forgive me if it's here somewhere that I could not locate). Anyway, here's my scenario:

I have Excel 2016. My workbook contains two pages:


  1. Sheet 1 - Data entry sheet. All data gets entered onto this sheet.
  2. Sheet 2 - The sheet that I print and give to the customer. This sheet is either one or two pages based on the amount of info I need to enter on the first page.

I have a macro that I currently use on sheet 2 in order to decide how many pages to print that I activate using radio buttons (appropriately named "print one page" and "print two pages". Here is my current macro:

Sub SetPrintAreaOnSheet2()
Select Case UCase(Sheets("Sheet2").Range("V5"))
Case "1"
ActiveSheet.PageSetup.PrintArea = "$A$1:$Y$56"
Case "2"
ActiveSheet.PageSetup.PrintArea = "$A$1:$Y$109"
End Select
End Sub

This macro works great as long as I select Sheet 2 and have the radio buttons on that sheet. I would like to be able to change the print area for sheet two, but have the radio buttons on sheet 1. However, by moving the radio buttons to Sheet 1, the macro does not change the print area on sheet 2. I assume that my problem lies where it says "ActiveSheet". What do I need to change in order to move the radio buttons to sheet 1 and still have them control the print area on sheet 2?

Thank you so much for your help!

Sincerely,

Bri2000
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Welcome to the forum. You are right, the bit you need to change is Activesheet.

Se the below revised code:

Code:
Sub SetPrintAreaOnSheet2()
    Select Case UCase(Sheets("Sheet2").Range("V5"))
        Case "1"
            Sheets("Sheet2").PageSetup.PrintArea = "$A$1:$Y$56"
        Case "2"
            Sheets("Sheet2").PageSetup.PrintArea = "$A$1:$Y$109"
    End Select
End Sub

You can put the radio buttons on sheet1 with no problems - theyw ill run the code from wherever they are.

Regards, John
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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