Very Simple VBA questions

Jzelenka

Board Regular
Joined
Jul 30, 2002
Messages
92
Hello,

2 very easy requests that I can not remember how to do:

1)Instead of referring to a worksheet by its tab name, I want to refer to the actual sheet. Under the excel objects, you have sheet1(name). I know how to refer to the sheet by its name, but am unsure how to refer to the sheet1 designation so that my code will work no matter what the tab name is.

2) I have done a recorded macro to set up the layout of one of the tabs at the press of a button. The last part of the code that I want it to do is set up the print area to the current region, no matter how many rows are added. I know the code for this is very easy but I can not get it to work...

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Jzelenka said:
Hello,

2 very easy requests that I can not remember how to do:

1)Instead of referring to a worksheet by its tab name, I want to refer to the actual sheet. Under the excel objects, you have sheet1(name). I know how to refer to the sheet by its name, but am unsure how to refer to the sheet1 designation so that my code will work no matter what the tab name is.

2) I have done a recorded macro to set up the layout of one of the tabs at the press of a button. The last part of the code that I want it to do is set up the print area to the current region, no matter how many rows are added. I know the code for this is very easy but I can not get it to work...

Thanks!

1. Sheet1.Select

2. ActiveSheet.PageSetup.PrintArea = ActiveCell.CurrentRegion.Address
 
Upvote 0

Forum statistics

Threads
1,221,700
Messages
6,161,378
Members
451,700
Latest member
Eccymarge

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