Dynamic table in macro

frank850102

New Member
Joined
Jan 26, 2010
Messages
7
Hi there

I have a table that requires inserting rows and deleting rows frequently, and extracting data from this table using Vlookup function.

In order to create this table as a dynamic table, I used "name manager" function. In the name manager, I typed the name of the table "Table 1", and the table range using "offset" function as OFFSET(Sheet1!$A$1,,,COUNT(Sheet1!$E:$E),10).

Now I want to create a macro that is able to adjust the print area of the spreadhseet such that it always prints only the "Table 1", not everywhere else. I don't want to use cell reference to define "Table 1" such as printarea. = "A1:J85", I would like the reference to be dynamic, such as the "OFFSET" function in the "Name Manager". Therefore, when I insert rows, it can still pick up the right print area for "Table 1".

I am not sure how to achieve this in VBA.

Please help.

Thank you very much.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Did you try?

Code:
ActiveSheet.PageSetup.PrintArea = Range("Table1").Address

Names can't contain spaces so I assumed your name was Table1.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

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