Command Button to print a range when the sheet name continues to change

mdlanclos

New Member
Joined
Aug 10, 2011
Messages
7
I have a worksheet with numerous calculations on it, and a final form, on the same sheet, which I want to print. I understand that I will have to create a command button with a print range in the code to print only that part that is the final product. However, I have a problem:

Each sheet will be for an individual patient. When I am performing the calculations, I will change the name (on the tab) from "Sheet1" to the patient name. I will then copy the entire sheet to another sheet (Sheet2), change the name to the appropriate patient, etc.

The problem I run into is that when I write the code for my command button, I have to have the name of the sheet in the code. Is there a way to have the name changed in the code. I hope I made this clear.

Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Why do you need to name the sheet? Why not just use ActiveSheet?

Code:
Private Sub CommandButton1_Click()
ActiveSheet.PageSetup.PrintArea = "$A1:$C7"
ActiveSheet.PrintOut
End Sub
 
Upvote 0
Thank you very much for your help. That worked perfectly.

One additional question; is there a way to have the button (Form Controls) to conditionally appear? In other words, if specific requirements have been met, the button will appear, otherwise, the button will not be available.

Thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,912
Members
452,949
Latest member
beartooth91

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