Excel VBA Relative Table Help

matmortel

New Member
Joined
Dec 16, 2015
Messages
2
Hi,

I'm trying to create a macro that will work dynamically with the number of rows of data. To try and combat this I inserted a table to house the data, so that all of the references after would be more dynamic, but I've found myself stuck with the creation of the table, as it wants to use defined values (my code is below):

ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$M$88"), , xlYes).Name = _
"Table1"

Can anyone help me to make the range dynamic so it will fit the table to the number of rows the data has (number of columns will always be consistent).

Hope you can help!

Thanks, Mat
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Does this work?
Code:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1").CurrentRegion, , xlYes).Name = _
"Table1"
 
Upvote 0
Hi Norie,

This almost works, but it ends up giving me an infinite number of empty rows below the table, so when I come to mailmerge from this list I have a large amount of blank data.
 
Upvote 0
Hi Mat

Not sure why you are wanting to Add the table in Code.
If you have already created the table (which is automatically dynamic), then you don't need to Add it again in your code, just refer to it by name
e.g.
With Sheets("Sheet1").ListObjects("table1")

substituting your sheet name and table name

will then allow you to do anything with that Table.
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,689
Members
449,250
Latest member
azur3

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