Resize table

2022

Board Regular
Joined
Jun 5, 2022
Messages
74
Office Version
  1. 2016
Platform
  1. Windows
I have a table in a tab called Sheet2 that looks as follows:

The text 'ID' in cell G2, the word 'Food' in H2.

Then the numbers 1 and 2 in G3 and G4, respectively.

And the words 'Chocolate' and 'Tomato' in H3 and H4, respectively.

When I created the table the range of cells in it, if you go to the 'Name Manager' are G3:H4 in Sheet2

And I would like to resize the table using VBA by extending the bottom of it to cover the number of rows added to in column G.

So if someone added a new value in cell G5 (eg the number 3, which would then mean you have 1. 2 and 3 in cells G2:G5), then code would increase the table size so that it would now cover cells G3:H5 instead of G3:H4.

Does anyone know how I can modify the code so that it expands the number of rows the table covers, based in new row entries in column G (using cell references eg "G1", instead of the exisiting cell notation)?

It currently gives an error when it gets to the line that starts "Set Table = ThisWorkbooks.Sheets("Sheet2").ListObjects("Table1")" (even though the table is called Table1).

VBA Code:
Sub resizetable()


Sheet2.Activate


Dim LastRow As Long

Dim Table As ListObject


LastRow = Cells(Rows.Count, "G").End(xlUp).Row


Set Table = ThisWorkbooks.Sheets("Sheet2").ListObjects("Table1")


Table.resize Range(Cells(3, 7), Cells(LastRow, 8))


End Sub




IDFood
1​
Chocolate
2​
Tomato
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,223,950
Messages
6,175,584
Members
452,653
Latest member
craigje92

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