Formatting Data with Variable Rows as Table

Adrianz1001

New Member
Joined
Nov 2, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello, I am trying to format data as a table in excel using VBA. The hope is that this macro will be used to format data as tables to run PivotTables from; however, the issue is that the tables will all have a different amount of rows. The table columns are fixed, but the rows are variable. Below is my current code. The testing data I am using is on Sheet1 and goes from A1:I265. As an example, I would need this to auto adjust for a table ranging from A1:I300. Any help would be greatly appreciated!

VBA Code:
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$I$265"), , xlYes).Name = "Table1"
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You could try
VBA Code:
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1").CurrentRegion, , xlYes).Name = "Table1"
There are unknown factors that would determine whether or not it will work as required.
 
Upvote 0
You could try
VBA Code:
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1").CurrentRegion, , xlYes).Name = "Table1"
There are unknown factors that would determine whether or not it will work as required.
That works! Thanks so much, I wouldn't have it imagined it be so simple.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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