VBA - Dynamic table size

carlito2002wgn

New Member
Joined
Aug 6, 2016
Messages
17
Hi,

I recorded a macro, and everything is working perfectly, except one thing! I have several sheets in a workbook that have data in columns A:P. The number of rows with data will vary each time that I run this macro. So, I might run it today with data in Sheet1 from A1:P100, but tomorrow Sheet1 might have data from A1:P200. How can I solve this problem?

This is a sample of what I have right now for three sheets from recording the macro:

Sheets("Albumin").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$100"), , xlYes).Name = _
"Table9"
Range("Table9[#All]").Select
Sheets("ALP").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$100"), , xlYes).Name = _
"Table10"
Range("Table10[#All]").Select
Sheets("ALT").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$100"), , xlYes).Name = _
"Table11"
Range("Table11[#All]").Select


Is the solution to change ie. Range("$A$1:$P$100") to Range("$A$A:$P$P") ?

Thank you for any help!!

Carlos
 
Last edited:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Carlos,

You might try using CurrentRegion to select your table range.
Code:
With Sheets("Albumin")
    .ListObjects.Add(xlSrcRange, .[A1].CurrentRegion, , xlYes).Name = "Table9"
End With
With Sheets("ALP")
    .ListObjects.Add(xlSrcRange, .[A1].CurrentRegion, , xlYes).Name = "Table10"
End With
With Sheets("ALT")
    .ListObjects.Add(xlSrcRange, .[A1].CurrentRegion, , xlYes).Name = "Table11"
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,018
Messages
6,128,305
Members
449,439
Latest member
laurenwydo

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